ttutisani / Xunit.Gherkin.Quick

BDD in .NET Core - using Xunit and Gherkin (compatible with both .NET Core and .NET)
MIT License
205 stars 29 forks source link

Async void step methods always pass #104

Closed csurfleet closed 3 years ago

csurfleet commented 4 years ago

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

ttutisani commented 4 years ago

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.

csurfleet commented 4 years ago

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

ttutisani commented 4 years ago

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

Megadesty commented 4 years ago

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.

ttutisani commented 3 years ago

Closing this as fixed by the PR linked above.