SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.22k stars 752 forks source link

Exceptions in async void step definitions are swallowed in SpecFlow v4 beta #2657

Closed gasparnagy closed 1 year ago

gasparnagy commented 1 year ago

SpecFlow Version

4.0 beta

Which test runner are you using?

xUnit

Test Runner Version Number

2.4.2

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

n/a

Issue Description

When an expection (e.g. assertion) is thrown from an async void step definition, the exception is caught by SpecFlow and the test shows an incorrect "pass" state.

Steps to Reproduce

[Then("something")]
public async void ThenSomething()
{
    Assert.Equal(1, 2); // throws exception
    await Task.Delay(10);
}

Link to Repro Project

https://github.com/gasparnagy/issue-repro-specflow-2600

gasparnagy commented 1 year ago

@SabotageAndi Maybe we should not allow async void step definitions at all in SpecFlow v4?

SabotageAndi commented 1 year ago

Good idea! Let's do it!

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.