How do You test it?
-all invocations in one method
-many methods that assert only part of check like testSomething, testSomethingTwoInvocations ...
|
How do You test it? -all invocations in one method -many methods that assert only part of check like testSomething, testSomethingTwoInvocations ... |
|||||
|
|
Each unit test should test one unit and one unit only. Say a test has three assertions based on three different things. If the first one fails, the next two will not be tested. Once the first one is fixed, the second may fail thus the third is not tested. If one had three separate tests, then a failure of one would not impact the running of the others. Edit: You get a little more typing (copy and paste) and the tests look bigger but that's about it. So, you do get a little more bloat. Do you care? |
|||
|
|
|
I usually do this encapsulated in a method where I give a count as parameter. Here is a simple example of a "fictional" ProductFactory class:
Refactoring the arrange code so that it is easy to invoke repetition is one way of removing duplicate test code. This way you can redo the invocation when you need to add more tests. Remember that you should refactor your test code as much as you do with production code. |
|||
|
|