Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The point of TDD is you can define the behavior before writing the code. ie. you define the expected result:

  def test_sum():
      assert sum(1, 2, 3) == 6
  def test_sum_no_args():
      assert sum() == 0
  def test_sum_negatives():
      assert sum(-1, -2) == -3
etc, and then you write the function.

This means you only do the "REPL" testing once ever for each case - and you can rerun the tests for all future changes. If ever type the same function + args into the REPL more than once - you have done redundant work and are wasting your time.

Likewise if you're in the habit of writing tests after your function is made - it shows you haven't put much thought, which means you haven't done the proper analysis of why the function exists, if the function is really one function or should be two functions, what arguments it can take, what it should return etc.



> if you're in the habit of writing tests after your function is made - it shows you haven't put much thought, which means you haven't done the proper analysis of why the function exists, if the function is really one function or should be two functions, what arguments it can take, what it should return etc.

I'd say that's a pretty broad brush you're painting there with


I'm not wrong.


I would say that you are, but you've convinced yourself otherwise.

But testing is important, for sure.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: