This post is the second of two parts (the first on MbUnit Attributes is here). There are many new, renamed, improved, combined, etc attributes in MbUnit v3. Jeff Brown et al have done a fantastic job with the newest versions of Gallio and MbUnit (download here). (These are not in any particular order.)

Assertions

Positive and Negative Tests

A nice, consistent update in version 3 is just about every Assertion has a correlated negative Assertion. For example, for AreEqual there is also AreNotEqual. Most of the names are obvious like this, except for a few logical differences (Assert.IsTrue and Assert.IsFalse).

Exceptions

I mentioned this transition from Attribute based exception handling to Assertion base in my last post, but I think it is worth repeating. This allows for more granular control of the test than simply decorating it with the ExceptedException attribute.

There are two flavors, Assert.Throws and Assert.DoesNotThrow. (Iâ€™ve never seen a use for the latter, but itâ€™s there).

[Test]

publicvoid Should_Test_For_Exception_Thrown()

{

var ex = Assert.Throws<ArgumentNullException>(

() => { thrownew ArgumentNullException(exMessage); });

}

Comparison Operators â€“ Single Values

There is a full suite of comparer assertions (see table below), and they essentially work the same way (see IntelliSense for more detailed information):