Timeline for Is it OK to have multiple asserts in a single unit test?
Current License: CC BY-SA 2.5
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 9, 2018 at 21:52 | comment | added | fourpastmidnight | And using a quality test runner such as NCrunch will show you exactly on what line the test failed, both in the test code and in the code under test. | |
| Oct 26, 2012 at 13:17 | comment | added | Anthony | Rule of thumb: if you have multiple assertions in a test, each one should have a different message. Then you don't have this problem. | |
| Sep 28, 2010 at 16:42 | comment | added | Guffa | @Richard: Getting a result and then extracting something from that result would be a process in several steps, so I covered that in the second paragraph in the answer. | |
| Sep 28, 2010 at 15:41 | comment | added | Richard | If you are combining multiple conditions into a single assert, then on failure all you know is that one failed. With multiple asserts you know specifically about some of them (the ones up to and including the failure). Consider checking a returned array contains a single value: check it is not null, then it has exactly one element and then then value of that element. (Depending on the platform) just checking the value immediately could give a null dereference (less helpful than the null assertion failing) and doesn't check the array length. | |
| Sep 28, 2010 at 14:05 | history | answered | Guffa | CC BY-SA 2.5 |