Alex Rivera | Logout

Is it bad practice to have more than one assertion in a unit test?

Asked 2009-04-17T23:03:41.477
54

Is it bad practice to have more than one assertion in a unit test? Does it matter?

Edit
Report

2 Answers

18

No it is not a bad practice. If the method you are testing returns a class, you should test the different variables that should have been set. For this purpose you might as well use one unit test.

If, however, you are testing several features in one unit test, it won't be as clear when it fails which features caused the problem. Remember unit tests are your friend, so let them help you. Make it easily available to see what went wrong so you can go fix it.

answered 2009-04-17T23:09:59.370
0

Put in all the asserts in that you want. Seriously.

I try to assert every step of the way up to and including the specific goal of my test.

answered 2009-04-18T00:16:04.797

Your Answer