September
2

I just found out that you can create compound constraints in NUnit (starting in v2.4). This means that you can logically group constraints.

For example, I am currently testing a custom IList<T> implementation, and in a specific test case, I want to make sure a specific entry exists instead of another. Before compound constraints, I would have written these 2 asserts:

Assert.That(this.subject, Has.Member(”rauchy”));
Assert.That(this.subject, Has.No.Member(”Omer”));

My problem with this code is that these two asserts represent a single fact - I want to make sure that rauchy makes it to the list, and not Omer. One might interpert them as two independent facts. With compound constraints, I can just write:

Assert.That(this.subject, Has.Member(”rauchy”) & Has.No.Member(”Omer”));

This way, you cannot think of this as two independent facts. Also, this helps follow the one-assert-per-test rule.

0