Started learning TDD and met some misunderstandings about different approaches for writing tests.
In some articles it is said that you should write new test for every case. So, there can be two or more tests for a single method.
Another approach that I saw, is about writing more complex tests in several steps. For example: write test -> fail -> write code -> success -> modify current test (add new assertions) -> fail -> write code -> success -> and so on. After this steps done test is covering a whole logic of a single method.
What are pros and cons of that approaches of using TDD?
It is “easier” to just add a bunch of assertions to an existing test case because you don’t need to create new test cases (and come up with names for them), but I would prefer to write smaller tests that are more specific. The main advantage is that you will have better information if/when a test fails about what went wrong.
Let’s see if I can come up with a contrived example:
As you can see, inventing good names for test methods is really hard (and I did a bad job especially for the last one), but just imaging what happens if
TheAnswer_AfterCreation_ShouldAdhereToTheHitchhikersGuidefails: you will get a pretty nice description from your test harness instead of the information thatTestEverythinghas failed (Challenge: try to come up with a better name for it 😉 )