与TFS 2010运行异步任务单元测试单元测试、任务、TFS

2023-09-03 02:13:45 作者:微凉离别意°

我写的是写在VS 2012针对.NET 4.0使用异步库的应用程序。

I am writing an application that is written in VS 2012 targeting .NET 4.0 using the Async library.

我的自动构建运行在TFS 2010生成代理,有VS 2012和.NET 4.5安装。

My auto builds run on a TFS 2010 build agent that has VS 2012 and .NET 4.5 installed.

我读无处不在,如果你的单元测试是异步它必须有异步任务TestMethod的()签名(而非异步无效TestMethod的() )。

I read everywhere that if your unit test is async it must have the async Task TestMethod() signature (rather than async void TestMethod()).

然而,当我这样做,我的构建服务器给了我这个错误的方法:

However when I do that my build server gives me this error for that method:

试验方法,公,不返回值和不应该采取任何参数。例如:公共无效Test.Class1.Test()

Test method marked with the [TestMethod] attribute must be non-static, public, does not return a value and should not take any parameter. for example: public void Test.Class1.Test().

我读这个和的这个这表明,如果你有一个.testsetting文件时,它可能会导致这个错误。但是,这两个说,他们是TFS / VS 2012。

I have read this and this that indicate that if you have a .testsetting file it can cause this error. But both of those say they are for beta versions of TFS/VS 2012.

另外,我需要我的测试设置文件,打开code覆盖。

Also, I need my test settings file to turn on code coverage.

这是一个TFS 2012嘛?可以在TFS 2010生成代理不使用VS 2012才能正确运行这些?

Is this a TFS 2012 only thing? Can the TFS 2010 Build agent not use VS 2012 to run these correctly?

有没有什么办法,使这项工作,而不必升级到TFS 2012?(我们仍然从该升级了几个月了)。

Is there any way to make this work without upgrading to TFS 2012? (We are still a few months out from that upgrade).

推荐答案

您可以使用类似于我描述的在我的博客:只是包装的$ C $下在每个单元测试 AsyncContext.Run (你可以得到 AsyncContext 从我的 AsyncEx的NuGet库)。

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).