Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add documentation for EnterMultipleScope #959

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down
22 changes: 22 additions & 0 deletions docs/snippets/Snippets.NUnit/MultipleAsserts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,26 @@
});
}
#endregion

#region MultipleAssertsScopes
[Test]
public void MultipleAssertsScopeDemo()
{
var situationUnderTest = new SomeCalculator();
var result = situationUnderTest.DoCalculation();

using (Assert.EnterMultipleScope())

Check failure on line 59 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 59 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 59 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 59 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for '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())

Check failure on line 66 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 66 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 66 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'

Check failure on line 66 in docs/snippets/Snippets.NUnit/MultipleAsserts.cs

View workflow job for this annotation

GitHub Actions / Build/Test Snippets

'Assert' does not contain a definition for 'EnterMultipleScope'
{
ClassicAssert.AreEqual(5.2, result.RealPart, "Real Part");
ClassicAssert.AreEqual(3.9, result.ImaginaryPart, "Imaginary Part");
}
}
#endregion
}
Loading