Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Test Explorer does not show up Async Unit Tests for metro apps

Tags:

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");
    }
}
like image 941
Spock Avatar asked Jun 16 '12 11:06

Spock


People also ask

How do I run a MSTest unit test?

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.

How do you add MSTest to a project?

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.

How do I add a test to test Explorer Visual Studio?

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.

How do you add unit tests?

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.


1 Answers

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

like image 178
svick Avatar answered Oct 04 '22 20:10

svick