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));
}

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)));
}

Failing asserts are shown. Goodbye, Assertion Roulette!
Installing
- Download the package,
- Copy Rauchy.Oapt.dll and Mono.Cecil.dll to the bin\net-2.0\addins directory under your NUnit installation folder,
- reference Rauchy.Oapt.dll from your test assembly.
#1 by Scott Jensen on May 29, 2010 - 2:09 pm
Quote
What an awesome idea, thank you!
#2 by Petr Roubal on June 6, 2010 - 5:32 pm
Quote
Hi, if i copy Mono.Cecil.dll and Rauchy.Oapt.dll to directory \bin\net-2.0\addins , so i get by starting NUnit GUI error:
System.IO.FileLoadException: Its not possible to load file or assembly nunit.framework, Version 2.5.5.10112
Exception HRESULT:0×80131040
#3 by Petr Roubal on June 6, 2010 - 6:30 pm
Quote
Hi, i have solved previous comment, in my project was reference to 2.5.3. nunit library …
but now i have other problem, when i try to run test:
in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
in System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
in NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)
in NUnit.Core.TestMethod.RunTestMethod(TestResult testResult)
in Rauchy.Oapt.OneAssertTestMethod.RunTestMethod(TestResult testResult)
in NUnit.Core.TestMethod.doTestCase(TestResult testResult)
I use DataDrivenTest
http://www.dotnetspider.com/resources/26499-Making-NUnit-test-cases-data-driven.aspx
[TestCase, ForEachAssert]
[TestCaseSource("TestCaseDataList")]
public void TestRow(
decimal rok, decimal mesic , decimal pojistne_poc_mesice, decimal nakupPoPJzaindex1,
decimal nakupPoPJzaindex2, decimal pojistneCelkem)
{
AssertOne.From(
() => Assert.AreEqual(
rok,
GetDecimalFromTable((int)mesic, 0)
)//,
() => Assert.AreEqual(
mesic,
GetDecimalFromTable((int)mesic, 1)
),
() => Assert.AreEqual(
pojistne_poc_mesice,
GetDecimalFromTable((int)mesic, 2)
)
);
}
#4 by Petr Roubal on June 6, 2010 - 6:36 pm
Quote
MyApplication.NUnit.Excel.TestAddition:
System.Reflection.TargetParameterCountException: Number of parameter does not match expected.
#5 by rauchy on June 9, 2010 - 6:22 am
Quote
@Petr – It was only tested on normal test cases so far, not data driven ones. If you feel like applying this fix yourself, go ahead. Otherwise I will do my best with it once I have some free time.
#6 by Peter Gfader on November 22, 2010 - 11:14 pm
Quote
Nice work! Good idea!
I wouldn’t recommend to have multiple assertions, but sometimes it makes life just easier…