I am writing an application that is written in VS 2012 targeting .NET 4.0 using the Async library.
My auto builds run on a TFS 2010 build agent that has VS 2012 and .NET 4.5 installed.
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 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().
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.
Also, I need my test settings file to turn on code coverage.
Is this a TFS 2012 only thing? Can the TFS 2010 Build agent not use VS 2012 to run these correctly?
Is there any way to make this work without upgrading to TFS 2012? (We are still a few months out from that upgrade).
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)
Update: Even better solution, use http://nuget.org/packages/Nito.AsyncEx/ and wrap with AsyncContext.Run(...)
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 getAsyncContext
from my AsyncEx NuGet library).