Not sure this is a known issue. I’m using VS2012 RC (Ultimate), and Win8 Release Preview. I have created a Unit Test Library (metro style app), and wrote a Unit Test, which include async/await keywords. However when I compile the Unit Test project, Unit Test Explorer does not show up the Test I wrote. If I exclude the async/await keywords, then the Unit Test Explorer shows up in the Test I just wrote. Has anyone come across with this before, or is it just me?
[TestClass]
public class UnitTest1
{
[TestMethod]
public async void SomeAsyncTest()
{
var result = await StorageFile.GetFileFromPathAsync("some file path");
}
}
To run MSTest unit tests, specify the full path to the MSTest executable (mstest.exe) in the Unit Testing Options dialog. To call this dialog directly from the editor, right-click somewhere in the editor and then click Options.
On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next. On the Configure your new project page, enter a name for your project, and then select Create.
If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.
To get started, select a method, a type, or a namespace in the code editor in the project you want to test, right-click, and then choose Create Unit Tests. The Create Unit Tests dialog opens where you can configure how you want the tests to be created.
Unit test methods that are async
have to return Task
, not void
.
That's because async void
methods are hard to track: there is no easy way for the unit testing library to find out that the test completed. (It's hard, but I think it's not impossible. You could do this by using a custom SynchronizationContext
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With