In a test that contains some asserts, for example:
Assert.AreEqual(1,1);
Assert.AreEqual(2,1);
Assert.AreEqual(2,2);
is it possible to let
No you can't do it with NUnit alone. You have to do something like @Konstantin Spirin said. I created a small extension that you can use; it's called NUnit-GroupAssert. It can be found here: https://github.com/slvnperron/NUnit-GroupAssert
How to use it:
[Test]
public void Verify_GroupsExceptions()
{
var group = new AssertGroup();
group.Add(() => Assert.AreEqual(10, 20));
group.Add(() => Assert.AreEqual(1, 1));
group.Add(() => Assert.AreEqual(3, 4));
group.Add(() => Assert.IsTrue(1 > 3));
group.Verify();
}
// OR
public void Verify_GroupsExceptions()
{
// Verifies on disposal
using (var group = new AssertGroup())
{
group.Add(() => Assert.AreEqual(10, 20));
group.Add(() => Assert.AreEqual(1, 1));
group.Add(() => Assert.AreEqual(3, 4));
group.Add(() => Assert.IsTrue(1 > 3));
}
}
it will output:
Test failed because one or more assertions failed:
1) Expected: 10
But was: 20
From Verify_GroupsExceptions at line 182) Expected: 3
But was: 4
From Verify_GroupsExceptions at line 203) Expected: True
But was: False
From Verify_GroupsExceptions at line 21