Run unit tests for Store apps in Visual Studio
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
This topic describes how to run unit tests by using the Test Explorer in Microsoft Visual Studio
The topics in this section describe the functionality of Visual Studio Express for Windows 8. Visual Studio Community, Enterprise, and Professional provide additional features for unit testing.
For more information, see Unit Test Your Code in the MSDN Library.
Visual Studio Express for Windows Store Apps includes the Microsoft unit testing frameworks for managed and for native C++ code. Test Explorer can run tests from multiple test projects in a solution and from test classes that are part of the production code projects. Test projects can be any combination of the Visual C++ or the Visual C# and Visual Basic unit test frameworks. When the code under test is written for the .NET Framework, the test project can be written in any .NET Framework language, regardless of the language of the target code. Native C/C++ code projects must be tested by using a C++ unit test framework.
When you build the test project, the tests appear in Test Explorer. If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer.
As you run, write, and rerun your tests, Test Explorer displays the results in default groups of Failed Tests, Passed Tests, Skipped Tests and Not Run Tests. You can change the way Test Explorer groups your tests.
You can perform much of the work of finding, organizing, and running tests from the Test Explorer toolbar.
You can run all the tests in the solution, all the tests in a group, or a set of tests that you select. Do one of the following:
To run all the tests in a solution, choose Run All.
To run all the tests in a default group, choose Run... and then choose the group on the menu.
Select the individual tests that you want to run, open the shortcut menu for a selected test and then choose Run Selected Tests.
The pass/fail bar at the top of the Test Explorer window is animated as the tests run. At the conclusion of the test run, the pass/fail bar turns green if all tests passed or turns red if any test failed.
As you run, write, and rerun your tests, Test Explorer displays the results in groups of Failed Tests, Passed Tests, Skipped Tests and Not Run Tests. The details pane at the bottom of Test Explorer displays a summary of the test run.
To view the details of an individual test, select the test.
The test details pane displays the following information:
The source file name and the line number of the test method.
The status of the test.
The elapsed time that the test method took to run.
If the test fails, the details pane also displays:
The message returned by the unit test framework for the test.
The stack trace at the time the test failed.
To display the source code for a test method in the Visual Studio editor, select the test and then choose Open Test on the shortcut menu (Keyboard: F12).
By default, Test Explorer displays your tests as child nodes of Failed Tests, Passed Tests, Skipped Tests and Not Run Tests.
|To group your tests by the time it takes to execute them, open the Group By list and choose Duration. Choose Test Outcome to switch to the original grouping.|
When you have a large number of tests, you can type in the Test Explorer search box to filter the list by the specified string. You can restrict your filter to specific types of strings by choosing from the filter list before you enter the search string.
You can use Test Explorer to start a debugging session for your tests. Stepping through your code with the Visual Studio debugger seamlessly takes you back and forth between the unit tests and the project under test. To start debugging:
In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug.
Because test methods can run in any order, set breakpoints in all the test methods that you want to debug.
In Test Explorer, select the test methods and then choose Debug Selected Tests on the shortcut menu.
For more information, about the debugger, see Debugging in Visual Studio.