Running Async Task unit tests with TFS 2010

旧时模样 提交于 2019-12-03 20:11:58

You can use an approach similar to what I described on my blog: just wrap the code for each unit test in an AsyncContext.Run (you can get AsyncContext from my AsyncEx NuGet library).

I had the same problem, I solved it with a ugly workaround thats works on the build server (just until you upgrade to tfs 2012)

[TestMethod]
public void TestMethod()
{
  //TODO: fix this after upgrade to TFS2012 build server
  var task = TestMethodInnerMethod();
  task.Wait();
}

private async Task TestMethodInnerMethod()
{
  //Arrange

  //Act
  await Provider.StartAsync();

  //Assert
}

Update: Even better solution, use http://nuget.org/packages/Nito.AsyncEx/ and wrap with AsyncContext.Run(...)

[TestMethod]
public void TestMethod()
{
  //TODO: fix this after upgrade to TFS2012 build server
  AsyncContext.Run(async () =>
  {
    //Arrange

    //Act
    await Provider.StartAsync();

    //Assert
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!