diff --git a/docs/articles/nunit/writing-tests/assertions/multiple-asserts.md b/docs/articles/nunit/writing-tests/assertions/multiple-asserts.md index f73eb8744..81b7b37b2 100644 --- a/docs/articles/nunit/writing-tests/assertions/multiple-asserts.md +++ b/docs/articles/nunit/writing-tests/assertions/multiple-asserts.md @@ -20,6 +20,10 @@ In that case, we could write a test with multiple assertions, such as: [!code-csharp[MultipleAssertsTests](~/snippets/Snippets.NUnit/MultipleAsserts.cs#MultipleAssertsTests)] +From NUnit 4.2 you can also use the new `EnterMultipleScope`: + +[!code-csharp[MultipleAssertsScopes](~/snippets/Snippets.NUnit/MultipleAsserts.cs#MultipleAssertsScopes)] + Functionally, this results in NUnit storing any failures encountered in the block and reporting all of them together upon exit from the block. If both asserts failed, then both would be reported. The test itself would terminate at the end of the block if any failures were encountered, but would continue otherwise. @@ -28,7 +32,7 @@ end of the block if any failures were encountered, but would continue otherwise. 1. The multiple assert block may contain any arbitrary code, not just asserts. -2. Multiple assert blocks may be nested. Failure is not reported until the outermost block exits. +2. Multiple assert blocks may be nested. Failure is not reported until the outermost block exits. 3. If the code in the block calls a method, that method may also contain multiple assert blocks. diff --git a/docs/snippets/Snippets.NUnit/MultipleAsserts.cs b/docs/snippets/Snippets.NUnit/MultipleAsserts.cs index dc66e12d6..c7750393c 100644 --- a/docs/snippets/Snippets.NUnit/MultipleAsserts.cs +++ b/docs/snippets/Snippets.NUnit/MultipleAsserts.cs @@ -48,4 +48,26 @@ public void MultipleAssertsDemo() }); } #endregion + + #region MultipleAssertsScopes + [Test] + public void MultipleAssertsScopeDemo() + { + var situationUnderTest = new SomeCalculator(); + var result = situationUnderTest.DoCalculation(); + + using (Assert.EnterMultipleScope()) + { + Assert.That(result.RealPart, Is.EqualTo(5.2)); + Assert.That(result.ImaginaryPart, Is.EqualTo(3.9)); + } + + // Can also work with the classic assertion syntax + using (Assert.EnterMultipleScope()) + { + ClassicAssert.AreEqual(5.2, result.RealPart, "Real Part"); + ClassicAssert.AreEqual(3.9, result.ImaginaryPart, "Imaginary Part"); + } + } + #endregion } \ No newline at end of file