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

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top