How to: Debug while a Test is Running
You can debug your code while a unit test is running. There are two ways to do this:
If the test is running under the smart device host on a device or emulator, use the procedure that is described in How to: Debug while Running a Smart Device Unit Test.
In all other cases, use the procedure that is described in this topic.
How to debug code while running a unit test
(Optional) Set one or more breakpoints in your code.
In the Test List Editor or the Test View window, select the unit tests for the methods you want to test. For information about opening either of these windows, see Team System Testing Tools Windows.
Press CTRL+R and then CTRL+T.
- or -
Next to the Run button in the Test View window, click the down arrow and select Debug Selection.
- or -
Right-click in the Test View window and then click Debug Selection.
- or -
Next to the Run button in the Test List Editor, click Debug Checked Tests.
- or -
Right-click in the Test List Editor and then click Debug Checked Tests.
- or -
On the Test menu, click Debug Tests or Debug All Tests.
The first unit test runs until a breakpoint is encountered in your code. While the test is running, you can use the usual debugging commands, such as Continue and Step Out. The unit test does not produce a final result until the code path through the method has been completed.
If you selected multiple tests in the Test View window or the Test List Editor, or if you clicked Debug All Tests, the test run continues with subsequent tests. In those tests as well, the test runs until encountering a breakpoint.
Note
You can do this only while you are running tests locally — on your own computer. In other words, you cannot debug while running tests remotely, by using a controller and an agent.