ttutisani/Xunit.Gherkin.Quick

Async void step methods always pass

csurfleet opened this issue · 5 comments

If you write your code like this:

[Given("I do something")]
public async void Do_Something() => throw new NotImplementedException();

the step will always pass.

I think this is something to do with how we consume the Task object - I'm happy to go fix it

I don't think that there is an easy way to fix it but go for it if you feel like it.

I know that you are going to make a couple of changes, please make sure to not mix them together. It is easier to review and merge separate pieces.

OK, I'll see what I can find. At the least I could definitely create a code warning for it in VS :)

Sure, give it a try and see how it goes and what we can get out of it.

I think you always have problems with async void methods, except in the one scenario that construct exists for in the first place (allowing WinForms callbacks to be async). It should be in the muscle memory of each programmer that after async always comes Task.
Other test frameworks like MSTest have unspecified behavior in this case, either the test just passes or is not executed at all without notifying. So XUnit.Gherkin.Quick is at least conform to that.

Closing this as fixed by the PR linked above.