nunit: Assert.Ignore breaks when a Task is returned w/o using async/await
Writing a test that invokes Assert.Ignore() and it fails with the following exception:
Stacktrace
NUnit.Framework.Internal.NUnitException : Rethrown
----> NUnit.Framework.IgnoreException : should not run
at NUnit.Framework.Internal.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args) in C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Reflect.cs:line 281
at NUnit.Framework.Internal.AsyncToSyncAdapter.Await(Func`1 invoke) in C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\AsyncToSyncAdapter.cs:line 77
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context) in C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Commands\TestMethodCommand.cs:line 84
--IgnoreException
at NUnit.Framework.Assert.Ignore(String message, Object[] args) in C:\src\nunit\nunit\src\NUnitFramework\framework\Assert.cs:line 214
at TestNUnit.Class1.Failing() in C:\Users\Sean\Desktop\TestNUnit\TestNUnit\Class1.cs:line 16
The failing test looks as the following:
[Test]
public Task Failing()
{
Assert.Ignore("should not run");
return Task.FromResult(1);
}
Changing the test to include the async keyword with await fixes this test:
[Test]
public async Task Working()
{
Assert.Ignore("should not run");
await Task.FromResult(1);
}
This fails with NUnit 3.11.0, but works with earlier versions. Tested with .NET Framework 4.5.2
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 27
Commits related to this issue
- Add nightly dev build of NUnit to verify issue with NUnit is addressed https://github.com/nunit/nunit/issues/3138 — committed to Particular/NServiceBus.AzureServiceBus by SeanFeldman 5 years ago