This project is read-only.


Support void-returning async test methods


Async tests which return Task are already supported, but it would be nice to also support async tests which return void.


JakeGinnivan wrote Jan 12, 2012 at 4:15 AM

I actually think that this should be explicitly failed. There is no way to await a async void test. If xUnit encounters this, it should fail the test.

If xUnit doesn't fail the test, the test throws after xUnit has moved on, bringing the xUnit process down.

BradWilson wrote Jan 23, 2012 at 4:29 PM

I have a way to await a void-returning async test. The method of detection is pretty much identical to the method of support (writing a custom sync context), so we might as well just support it.

JakeGinnivan wrote Jan 24, 2012 at 12:50 AM

Clever.. When are you planning to do this? I would be interested to look at the code for another problem domain.

BradWilson wrote Jan 24, 2012 at 11:54 PM

v.Next (which looks right now like 2.0).

The key is that void-returning async methods call SynchronizationContext.Current.OperationStarted and OperationCompleted to mark the beginning and end of the async code execution. If you register a custom synchronization context, you'll be able to detect this fact.

AArnott wrote Dec 6, 2012 at 4:48 PM

Here is a link to a blog post on just how to do this:

BradWilson wrote Aug 19, 2013 at 12:51 AM

Fixed in commit b6784a4.