我們正在試圖獲得以下scenrio一步打破測試的情況下,故障發生DoAyncStuff()
方法中:Specflow用的await步驟異步API
[Given(@"There is something")]
public async Task GivenSomething()
{
await DoStuff();
}
private async Task DoStuff()
{
await Task.Run(() => Thread.Sleep(1000));
throw new ApplicationException("Boom");
}
但它實際上使一個快樂的綠色運行,直到你使用.Wait()
或.Result
:
[Given(@"There is something")]
public void GivenSomething()
{
DoStuff().Wait();
}
這個問題似乎是在NUnit的生成規格,看起來像這樣:
public virtual void SomethingAsync()
{
...
testRunner.Given("There is something", ...);
...
}
這似乎與下面的代碼工作:
public virtual async Task SomethingAsync()
{
...
await this.ScenarioSetup(scenarioInfo);
...
}
上面的代碼是手動編輯自動生成的文件,所以我實際上是尋找一種方法來自動生成下面的代碼。
The documentation似乎是可供asyncronous API唯一的選擇,但它實際上是對Silverlight和,據我瞭解使用某種類型的API,而我們會preffer使用本機C#等待關鍵字。
有沒有辦法處理本機async/await
是SpecFlow的步驟?
看看[this](https://github.com/techtalk/SpecFlow/pull/647)發佈 –