Export (0) Print
Expand All

How to: View a Stack Trace and Navigate to Point of Failure

Visual Studio 2008

After you run a unit test and receive a failed result, you can view a stack trace to see contextual information about the failure in the test. You can also navigate directly to the point of failure in the test.

NoteNote:

Stack traces are available only for unit tests. 

The stack trace is displayed on the Test Results Details page in Visual Studio. Stack traces are also written verbatim to the test results (*.trx) file for that test run. This means that if you open a test results file in Visual Studio, you can view the stack trace that was logged for that test run.

Stack Trace Contents

A stack trace displays a list of methods that represent the chain of execution during the test run. Displayed at the bottom of the stack trace is the first method that was encountered during the test run. This is usually the test method itself. The sequence of methods continues upward to the top of the stack trace, where you see the method that represents the point of failure. By examining this sequence, you can usually gain insight into the cause of the failure.

The Point of Failure

The point of failure is a line of code that caused the test to fail in one of these ways:

  • It contains an Assert statement that failed and threw an exception that was not caught.

  • It contains code that threw an exception that was not caught.

Prerequisites

To see the stack trace for a test and to navigate to the point of failure, the following prerequisites must be satisfied:

  • To view a stack trace for a test, the test must produce a Failed or Inconclusive result. Stack traces are not available for tests that pass.

  • The display the point of failure, the option to do this must be enabled, as follows: On the Tools menu, click Options. In the Options dialog box, expand Test Tools and then click Test Execution. Under Test Results Management, click Double-clicking a unit test displays the point of failure in the test.

  • Debug symbols must be present for your test project. When you build your project, debug symbols are written to a file that has the extension .pdb. This file appears the bin\debug directory under your test project. Also, code in the assembly that is compiled from your test project might call code in another assembly. In this case, debug symbols for the called assembly must be available also. For more information about .pdb files, see PDB Files (C# and Visual Basic).

    NoteNote:

    In a build or test lab, you might run tests for which you have only the test metadata file and a test project's assembly but no .pdb file. In this case, you cannot view a stack trace nor double-click to navigate to the point of failure.

To view a stack trace

  1. Run a unit test.

  2. In the Test Results window, right-click the test and click View Test Results Details.

    The Test Results Details page opens in the main editing window. The Error Stack Trace pane of the Test Results Details page displays the stack trace. Each line in the stack trace also displays a hyperlink to a line in source code.

  3. (Optional) Click a hyperlink in the stack trace to see the method that was called at that point in the run of this unit test.

To navigate to the point of failure

  1. Run a unit test.

  2. In the Test Results window, double-click the test. This opens the source file at the point of failure.

    - or -

    In the Test Results window, right-click the failed test and click View Test Results Details.

    The Test Results Details page opens in the main editing window. The Error Stack Trace pane of the Test Results Details page displays the stack trace. Each line in the stack trace also displays a hyperlink to a location in source code.

  3. Click the hyperlink in the top line of the stack trace. This opens the source file at the point of failure.

Community Additions

ADD
Show:
© 2014 Microsoft