Do you run Unit Tests in Visual Studio?

Last updated by Lee Hawkins [SSW] almost 2 years ago.See history

When you build the test project in Visual Studio, the tests appear in Test Explorer. If Test Explorer is not visible, choose Test | Windows | Test Explorer.

vs test explorer
Figure: Test Explorer in Visual Studio

As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of ProjectNamespace, and Class. You can change the way the Test Explorer groups your tests.

You can perform much of the work of finding, organizing and running tests from the Test Explorer toolbar.

test explorer toolbar
Figure: Use the Test Explorer toolbar to find, organize and run tests

You can run all the tests in the solution, all the tests in a group, or a set of tests that you select:

  • 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 context menu for a selected test and then choose Run Selected Tests.

Tip: If individual tests have no dependencies that prevent them from being run in any order, turn on parallel test execution in the settings menu of the toolbar. This can noticeably reduce the time taken to run all the tests.

test explorer parallel runs
Figure: turn on "Run Tests In Parallel" to reduce the elapsed time to run all the tests

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 or side of the Test Explorer displays a summary of the test run.

Tip: If you are using dotnet Core/5+, you can run tests from the command line by running dotnet test

We open source. Powered by GitHub