Dela via


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 your production code or the test itself is running in either an IIS process or in the ASP.NET Development Server process, use the procedure that is described in How to: Debug while Running a Test in an ASP.NET Solution.

  • In all other cases, use the procedure that is described in this topic.

How to debug code while running a unit test

  1. (Optional) Set one or more breakpoints in your code. 

  2. In the Test List Editor or the Test View window, select the unit tests for the methods you want to test.

  3. 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, that is, on your own computer. You cannot debug while you are running tests remotely, by using a test controller and test agents.

See Also

Tasks

How to: Run Automated Tests from Microsoft Visual Studio

How to: Debug while Running a Test in an ASP.NET Solution