Question

I have started practicing TDD in one of my play project. It is really interesting. However I do not understand, why we should start with a failing test? Is it because it's a rule and we have to follow that, or is there any philosophy behind this? Please share your ideas.

Regards, Rajib

Was it helpful?

Solution

It is to prove that the test itself is in fact doing its job.

If the test passes before you've written or changed any code then clearly the test is not very effective, so write the test, ensure that it fails, then write the code to satisfy the test.

Really, with TDD, each piece of code you write should be to fix a failing test. This way you ensure that your code is fully tested.

OTHER TIPS

You write a failing test case in order to observe that the test case CAN fail.

This is dramatized in episode 22, "TDD with a Stackoverflow Master Programmer." If you're interested in TDD, you'll enjoy the entire audio drama on Agile Thoughts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top