This topic explains how to step through C++test test cases with a debugger to better examine the code's internal state during a given test. For example, you might want to debug test cases to learn more about how C++test obtained an unexpected outcome, or to determine why a test case failed. You do not need to manually add breakpoints to the code. C++test will automatically set the breakpoints at the beginning of each test case that you select for execution.
Sections include:
Table of Contents | ||
---|---|---|
|
Configuring Debugger Settings
Anchor | ||||
---|---|---|---|---|
|
To enable debugging inside Visual Studio IDE
- Open test configuration you use for running test cases
- Choose the Execution> Runtime tabs
- Enable the Run tests in debugger(*) option.
Executing Tests with a Debugger
Anchor | ||||
---|---|---|---|---|
|
This section covers debugging tests in native development environments. For information about debugging tests in embedded environments see Debugging Test Cases.
To execute a test with the Visual Studiodebugger:
- Prepare a "Debug Unit Tests" Test Configuration.
- Either use the built-in "Debug Unit Tests" Test Configuration or develop a custom Test Configuration by duplicating the built-in configuration and customizing it as described in the Configuring Test Configurations and Rules for Policies.
- Run your preferred "Debug Unit Tests" Test Configuration as follows:
- Select test case(s) that you want to debug in one of the following ways:
- Select the test case in the Test Case Explorer.
Select the test case function name in the code editor.
Select the test case function in the Class view. Note that these functions will be located under the Testsuite classes, not under the classes corresponding to the original source.
Launch your preferred "Debug Unit Tests" Test Configuration. For example, right-click the selection, then use the Parasoft shortcut menu to run the preferred Test Configuration. C++test will then launch appropriate debugger and automatically set the break-points at the beginning of each selected test case function.
- Select test case(s) that you want to debug in one of the following ways:
Use standard debugger features to step through the test case.
Note icon false - The debugger will be activated only if the debugging Test Configuration is run on a selection of one or more test cases. Otherwise, the following warning will appear in the console output and the execution will continue without debugging:
Warning: debugger will not be activated - no valid breakpoints found. Select (test case) function definitions to set breakpoints.
- The debugger will be activated only if the debugging Test Configuration is run on a selection of one or more test cases. Otherwise, the following warning will appear in the console output and the execution will continue without debugging: