Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TestMethod: async Task TestSth() does not work with .NET 4.0

I'm trying to run asynchronous test methods with .NET 4.0 BCL Async and MsTest.

It seems that this setup is not able to deal with [TestMethod] async Task TestSth() due to a missing entry in the test case explorer. After changing the signature to async void, I can run the the test case but with the wrong outcome (no errors will be reported at all).

I have seen an attemt at Running Async Task unit tests with TFS 2010 but I think there should be a prettier way to tackle the problem.

Any suggestions?

like image 372
Philipp P Avatar asked Mar 17 '14 15:03

Philipp P


1 Answers

You can only use the async keyword with an MSTest-referencing class library targeting .NET 4.5.

If you can't use .NET 4.5 for whatever reason, then you'll just have to live with waiting on the tasks manually.

And even if the production code (i.e. the code under test) can't use .NET 4.5, why can't the test project do so? If you already have VS 2012+ available to you, then .NET 4.5 will be installed on your development machine.

like image 150
Martin Costello Avatar answered Oct 02 '22 13:10

Martin Costello