I have a series of unit tests that connect to an Azure Storage emulator. In Setup my code checks if there is something listening on the emulator's port, and if not sets a flag StorageNotAvailable
.
In each of my tests I have some code...
if ( StorageNotAvailable )
Assert.Inconclusive( "Storage emulator is not available" )
// where storage emulator is available, continue as normal
As expected, when the test returns void
this reports correctly in the Test Explorer as "Inconclusive".
When the test is exercising some async methods, and the [TestMethod]
signature returns Task
then the test is reported in the TestExplorer as "Failed" instead of "Inconclusive".
How can I get an async method to report as Inconclusive?
Some additional detail may be in order. Here are some sample tests I rigged up to demonstrate the problem I am seeing.
[TestMethod]
public void MyTestMethod()
{
Assert.Inconclusive( "I am inconclusive" );
}
[TestMethod]
public async Task MyTestMethodAsync()
{
Assert.Inconclusive( "I am an error" );
}
Some environment details may be in order as well:
Assert.Inconclusive
raises a special kind of exception, which will cause the task to catch that exception. Since the Task library and async don't know about, we can't blame them for complaining. The Task framework will wrap the exception in an AggregateException, which I suspect is getting reported. This was a nice assumption, but it turned out that the code looking for AssetInconclusiveException was comparing the raised instance against MstestV1's implementation and not MsTestV2.
But I suppose this should be considered a bug in the MsTest v2 runner, which should inspect all Tasks that failed and look at the exception that caused their failure.
The behaviour is a known behaviour at the moment and I've just submitted a PR to fix this. Pull Request Merged, now just wait for the next Nuget build to trigger.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With