Visual Studio 2008 (Professional Edition and above) provides a really nice set of tools for development and execution of unit tests.
[To begin with an overview of unit testing, start here.]
This prior post demonstrates how to build a unit test using the "Create Unit Tests..." feature of the Code Editor. This post demonstrates how to execute a unit test.
NOTE: This post assumes you have already generated or created at least one unit test.
To execute one or more unit tests:
1) Open your solution in Visual Studio.
The solution should include both the project(s) to test and the test project(s).
2) Select Test | Windows | Test View from the menu to view the Test View window. This window contains every method marked with the TestMethod attribute.
The solution used for the screenshot above has two LastNameTest unit tests: One for the VB example and one for the C# example. If you coded along from the prior unit testing post, you will only have one for whichever language you selected. If you have been creating unit tests for one of your projects, you may have hundreds of tests in this list.
To execute unit tests:
1) Select one or more tests from the list of tests in the Test View window.
You can add columns and sort the list or use the filter feature to make it easier to locate and select the desired tests to execute.
2) Click the Run Selection button in the upper left corner of the Test View window or right-click on any selected test and select "Run Selection" from the context menu.
The selected test(s) will then execute, displaying their status in the Test Results window:
When the test is complete, the Test Results window will look something like this:
Both of the tests shown in the above screenshot are marked as Inconclusive because the generated unit testing code used the Assert class Inconclusive method. The generated unit testing template is designed to prevent a false positive. It generates an inconclusive result until you update the unit test with correct valid and invalid values and remove the Inconclusive method call.
To see more information on the result of the test, double-click on a test result.
To run the test again, use the Run or Debug buttons at the top of the Test Results window.
If any of the tests don't pass, they are marked as Failed in the Test Results window as shown below.
Double click on any of the failed tests to view the test results:
The Error Stack Trace at the bottom of this window gives you further information on the source of the failure. Click on any link in the stack trace to jump to the associated location in the code.
You can also debug the code as the test is executing if you "Debug Selection" option instead of the "Run Selection" option.
After you update the unit tests with valid code and the tests pass, the Test Results will appear as follows:
Notice the color-coded green passing indicator.