Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Can't use Assert.Multiple with async code #2348
Passing an async lambda into Assert.Multiple compiles fine with no warnings but always passes instantaneously, even if the code inside the lambda should fail.
Sample test code:
I would intuitively expect both these tests to take 5 seconds to run before then failing. However, only TestMultipleSync fails; TestMultipleAsync passes successfully in less than a second. Output from console runner:
I guess the lambda is being interpreted as an "async void" rather than an "async Task" and so its results end up ignored? There doesn't seem to be any obvious other way of doing an async multiple assert though - most of the other Assert methods that take a TestDelegate have an equivalent AsyncTestDelegate method (Catch/CatchAsync, DoesNotThrow/DoesNotThrowAsync), but there's no MultipleAsync method.
There's also nothing on the documentation page for Multiple Asserts (https://github.com/nunit/docs/wiki/Multiple-Asserts) which calls out that you can't use it with async code - on the contrary, it says the assert block "may contain any arbitrary code".
Using NUnit 3.7.1, console runner 3.7.0.