Skip to content

Commit

Permalink
Merge pull request #4344 from stevenaw/stevenaw/tests-for-assertmulti…
Browse files Browse the repository at this point in the history
…ple-scopes

Add a test to verify Assert.Multiple only throws for failures in current scopes
  • Loading branch information
mikkelbu committed Apr 23, 2023
2 parents fda616f + 4e2d231 commit bc6d65b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/NUnitFramework/tests/Assertions/AssertMultipleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Threading.Tasks;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.TestData.AssertMultipleData;
using NUnit.TestUtilities;
using AM = NUnit.TestData.AssertMultipleData.AssertMultipleFixture;
Expand Down Expand Up @@ -131,6 +132,30 @@ private ITestResult CheckResult(string methodName, ResultState expectedResultSta

return result;
}

[Test]
public void AssertMultiple_OnlyThrowsForCurrentScope()
{
try
{
// Place one failure in the context
Assert.That(false);
}
catch { }

var currentResult = TestExecutionContext.CurrentContext.CurrentResult;
var previousFailureCount = currentResult.AssertionResults.Count;
Assume.That(previousFailureCount, Is.GreaterThan(0));

Assert.Multiple(() => { });

// The assert multiple shouldn't've triggered a failure
Assert.That(currentResult.AssertionResults.Count, Is.EqualTo(previousFailureCount));

// If we get this far, the test is good so we should clean up the context from the intentional failure above
currentResult.SetResult(null, null, null);
currentResult.AssertionResults.Clear();
}
}

[Explicit("Used to display error messages for visual confirmation")]
Expand Down

0 comments on commit bc6d65b

Please sign in to comment.