Proper unit tests should fail for exactly one reason, that’s why you should be using one assert per unit test.

However, sometimes you want to test several behaviors that share the same arrange and act block, but differ in their assert block. (You do know about Arrange, Act, Assert, right?)

If you follow the “one assert per test” guideline, you probably¬†found yourself duplicating test methods and changing the assert block, or perhaps you extracted your arrange and act blocks into helper methods.

Oapt saves you this trouble by running your unit tests several times, each time using one assert and ignoring the rest.

Before

[TestCase]
public void should_parse_single_element()
{
	var parser = new MySuperParser();

	var element = parser.Parse("<single />");

	Assert.That(element.IsEmpty);
	Assert.That(element.Name, Is.EqualTo("single"));
	Assert.That(element.ChildNodes, Has.Count.EqualTo(0));
}
Before

Some asserts fail, causing the entire unit test to fail

After

[TestCase, ForEachAssert]
public void should_parse_single_element()
{
	var parser = new MySuperParser();

	var element = parser.Parse("<single />");

	AssertOne.From(
		() => Assert.That(element.IsEmpty),
		() => Assert.That(element.Name, Is.EqualTo("single")),
		() => Assert.That(element.ChildNodes, Has.Count.EqualTo(0)));
}
After

Failing asserts are shown. Goodbye, Assertion Roulette!

Installing

  1. Download the package,
  2. Copy Rauchy.Oapt.dll and Mono.Cecil.dll to the bin\net-2.0\addins directory under your NUnit installation folder,
  3. reference Rauchy.Oapt.dll from your test assembly.