4

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?

marked as duplicate by gnat, Arseni Mourzenko, user40980, GlenH7, Kilian Foth Jan 1 '15 at 14:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8

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.