Steps to process pending async API

We are trying to get the next step in the script to break the test if a failure occurs in the DoAyncStuff() method:

 [Given(@"There is something")] public async Task GivenSomething() { await DoStuff(); } private async Task DoStuff() { await Task.Run(() => Thread.Sleep(1000)); throw new ApplicationException("Boom"); } 

But actually it makes the green move happy until you use .Wait() or .Result :

 [Given(@"There is something")] public void GivenSomething() { DoStuff().Wait(); } 

The problem is that the generated NUnit specification looks like this:

 public virtual void SomethingAsync() { ... testRunner.Given("There is something", ...); ... } 

which seems to work with the following code:

 public virtual async Task SomethingAsync() { ... await this.ScenarioSetup(scenarioInfo); ... } 

The above code has been manually edited by an automatically generated file, so I'm really looking for a way to create the following code automatically.

The documentation is apparently the only option available for the asynchronous API, but in fact for Silverlight, and as I understand it, uses some kind of API, while we would prefer to use the native C # wait keyword.

Is there a way to handle async/await natively these are SpecFlow steps?

+5
source share
1 answer

In the current version of the released version (2.1) there is no async support and expectations, support (via this unified PR ) in v2.2 is added, which is available from the CI server , but there is no official release yet.

2.2 has been released and supports asynchronous expectations in tests.

+6
source

Source: https://habr.com/ru/post/1258183/


All Articles