Is it OK to have multiple asserts in a single unit test?
Posted
by
Restuta
on Programmers
See other posts from Programmers
or by Restuta
Published on 2010-09-28T10:22:32Z
Indexed on
2012/10/26
17:20 UTC
Read the original article
Hit count: 365
unit-testing
I think that there are some cases when multiple assertions are needed (e.g. Guard Assertion), but in general I try to avoid this. What is your opinion? Please provide a real word examples when multiple asserts are really needed. Thanks!
Edit
In the comment to this great post Roy Osherove pointed to the OAPT project that is designed to run each assert in a single test.
This is written on projects home page:
Proper unit tests should fail for exactly one reason, that’s why you should be using one assert per unit test.
And also Roy wrote in comments:
My guideline is usually that you test one logical CONCEPT per test. you can have multiple asserts on the same object. they will usually be the same concept being tested.
© Programmers or respective owner