Is it good practice to have multiple test cases in one test or should I always create one test for single test case in every situation even if it is redundant? Why?


1 Answer 1


The common approach is to put each independent test in its own test method. The main reason for this is to make the list of passing/failing tests as self-documenting as possible. Ideally you should be able to look at which test failed and have a good idea what is wrong with the code from that alone. If single test methods test multiple things, this is not possible.

Sometimes it happens that two tests have identical setup; in this case it is recommended to factor out the common code into a helper method.

Not the answer you're looking for? Browse other questions tagged or ask your own question.