2oo*_*oom 10 c# bdd nunit specflow async-await
我们试图通过以下方法来打破测试,以防DoAyncStuff()方法中发生故障:
[Given(@"There is something")]
public async Task GivenSomething()
{
await DoStuff();
}
private async Task DoStuff()
{
await Task.Run(() => Thread.Sleep(1000));
throw new ApplicationException("Boom");
}
Run Code Online (Sandbox Code Playgroud)
但它实际上是一个快乐的绿色运行,直到你使用.Wait()或.Result:
[Given(@"There is something")]
public void GivenSomething()
{
DoStuff().Wait();
}
Run Code Online (Sandbox Code Playgroud)
问题似乎出现在NUnit generated-spec中,如下所示:
public virtual void SomethingAsync()
{
...
testRunner.Given("There is something", ...);
...
}
Run Code Online (Sandbox Code Playgroud)
这似乎与以下代码一起使用:
public virtual async Task SomethingAsync()
{
...
await this.ScenarioSetup(scenarioInfo);
...
}
Run Code Online (Sandbox Code Playgroud)
上面的代码是手动编辑的自动生成的文件,所以我实际上正在寻找一种自动生成以下代码的方法.
该文档似乎是asyncronous API唯一可用的选项,但实际上它适用于Silverlight,据我所知使用某种API,而我们更喜欢使用本机C#await关键字.
是否有一种方法可以原生处理async/awaitSpecFlow步骤?