1

I have API integration tests in nUnit. When I added execute async method in [TearDown] I saw that await operator doesn't work ...

[TearDown]
public async void TearDownAsync()
{
  var response = await service.GetTasksAsync();

  if (response.Count > 0)
  {

  }
}

In this sample method GetTasksAsync() is executed but doesn't wait for result. When I change it to use Wait() it's ok.

[TearDown]
public void TearDown()
{
  var response = service.GetTasksAsync();
  service.Wait();

  if (response.Result.Count > 0)
  {

  }
}

I think the problem is in the[TearDown]. Method is executed but thread is ended prematurely. In [Test] method everything is ok. Is it a bug in [TearDown] or I'm using it improperly?

lucask
  • 2,290
  • 24
  • 19
Mariusz
  • 442
  • 5
  • 16

0 Answers0