-
Notifications
You must be signed in to change notification settings - Fork 744
Assert.Multiple method should fail only if a contained assertion failed #4264
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
Comments
Thanks @rockstome this one is particularly curious. It looks like [Test]
public void Test()
{
System.Console.WriteLine("Test 1");
try
{
Assert.That(false);
}
catch { }
System.Console.WriteLine("Test 2");
Assert.Multiple(() => { });
System.Console.WriteLine("Test 3");
} That said, I'm not sure if I'd call this a bug per se or that it's working by-design. One almost has to "force" this to fail wholly within a test by suppressing a previous assertion failure from outside the multiple block like in the example. I don't know if it was ever considered how Your example is obviously a minimal repro which is appreciated, but to help understand how you originally hit this: is there something you're needing to assert in your TearDown that can't be handled elsewhere? |
Changing your Test to not fail, causes both if (context.MultipleAssertLevel == 0 && context.CurrentResult.PendingFailures > 0) Other places in NUnit remember the count before running their own code and only report if the errors increased: // If there are new assertion results here, they are warnings issued
// in teardown. Redo test completion so they are listed properly.
if (context.CurrentResult.AssertionResults.Count > oldCount)
context.CurrentResult.RecordTestCompletion(); So maybe we need to update the two implementation of |
Good catch, thanks @manfred-brands ! I agree, it's expected that |
Please note that we have often discouraged assertions in the teardowns - see e.g. #3957 or #2938 - but that being said @manfred-brands proposal sounds reasonable. |
Uh oh!
There was an error while loading. Please reload this page.
Here is code
What is very strange for me, line where "Teardown 2" should be printed is not executed. Why is this happening? Assertion in teordown is not throwing any exception
The text was updated successfully, but these errors were encountered: