Interested in a
Personal Demo ?


Name* :
Please Enter your Name
Company E–Mail* :
Please Enter a Valid Email

Testimonials


"I find a new use for Typemock each time I use it... It's not often a product fills a gap so well… I was impressed. It takes care of a big hole in unit testing"
John Spano, CTO and Co-Founder, NeoTekSystems
Success stories

PurchaseOptions


US Toll Free
866–895–4680
Outside US
+44–203–150–0293
Get your printable quote
Buy online

 

Avoid Multiple Asserts

you can also think about this rule as "Assert again only one logical concept at a time" - you can have multiple asserts, if they are all on the same object - you're still testing only one unique concept in the application, but if you have asserts on more than one object in the application you're really testing more than one thing - and you might want to split the test into several different tests.

Asserts throw exceptions

Another good reason to try and avoid multiple asserts altogether, is that when you have more than one assert in a test, if the first one fails, it throws an exception, and the other asserts are never executed. That means that you will only see the first failure, but you won't know if the other asserts would have passed or not - because they were never executed.

An example of when multiple asserts are OK:

 

Person p1 = new Person();
Person p2 = new Person();

Assert.AreEqual("name", p1.Name);
Assert.AreEqual(1,p1.Age);

 

An example of multiple asserts on different objects (not OK):

 

Person p1 = new Person();
Person p2 = new Person();

Assert.AreEqual("name", p1.Name);
Assert.AreEqual("name", p2.Name);