Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TDD. When you can move on?

Tags:

tdd

When doing TDD, how to tell "that's enough tests for this class / feature"?

I.e. when could you tell that you completed testing all edge cases?

like image 529
alex Avatar asked Sep 25 '08 20:09

alex


People also ask

Why is TDD so hard?

Basically, TDD is hard! It needs skill, and it needs practice. The good news is that TDD rewards the effort. Once you get over the hurdle of working incrementally and writing fine-grained tests (hard), you'll find the implementation slots into place.

What is the rule of test driven development?

Robert C. Martin, who is known as Uncle Bob, describes these Three Laws of TDD: You are not allowed to write any production code unless it is to make a failing unit test pass. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.

Why TDD is not usually used?

This means the following problems in such a TDD approach: More test code than the implementation code. Not easy to design tests before the implementation is done. Implementation refactoring breaks existing tests.


1 Answers

With Test Driven Development, you’ll write a test before you write the code it tests. Once you’re written the code and the test passes, then it’s time to write another test. If you follow TDD correctly, you’ve written enough tests once you’re code does all that is required.

As for edge cases, let's take an example such as validating a parameter in a method. Before you add the parameter to you code, you create tests which verify the code will handle each case correctly. Then you can add the parameter and associated logic, and ensure the tests pass. If you think up more edge cases, then more tests can be added.

By taking it one step at a time, you won't have to worry about edge cases when you've finished writing your code, because you'll have already written the tests for them all. Of course, there's always human error, and you may miss something... When that situation occurs, it's time to add another test and then fix the code.

like image 117
Josh Sklare Avatar answered Oct 21 '22 08:10

Josh Sklare