Interested in a
Personal Demo ?


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

Testimonials


"Typemock has helped us get some difficult to test code under test, as well as speed up the writing of some business rules/classes. The new version is quite impressive with the suggested tests. Any tool that helps you write more (and better!) tests has got to help make better quality code." 
Stephen Price Lead Developer at Unlisted Marketplace
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);