Run, debug, terminate tests
Quick way
If your tests don't require any specific actions before start and you don't want to configure additional options, such as code coverage, you can run them by using the following options:
Place the caret at the test class to run all tests in that class, or at the test method, and press Control+Shift+F10. Alternatively, click the gutter icon next to the test class or test method.
The gutter icon changes depending on the state of your test:
The gutter icon marks new tests.
The gutter icon marks successful tests.
The gutter icon marks failed tests.
To run all tests in a folder, select this folder in the Project tool window and press Control+Shift+F10 or select Run Tests in 'folder' from the context menu .
Customizable way
When you run a test, CLion creates a temporary run configuration. You can save temporary run configurations, change their settings, share them with other members of your team. For more information, refer to Run/debug configurations.
Create a new configuration for tests or save a temporary one.
From the list on the main toolbar, select the configuration you want to run.
Click or press Shift+F10.
After CLion finishes running your tests, it shows the results in the Run tool window on the Test Runner tab. For more information on how to analyze test results, refer to Explore test results.
Stop tests
Use the following options on the Run toolbar of the Test Runner tab:
Click or press Control+F2 to terminate the process immediately.
Click to terminate the process gracefully, allowing shutdown hooks to run.
Rerun tests
Rerun a single test
Right-click a test on the Test Runner tab of the Run tool window and select Run 'test name'.
Rerun all tests in a session
Click on the Run toolbar or press Control+F5 to rerun all tests in a session.
Rerun failed tests
Click on the Run toolbar to rerun only failed tests.
Hold Shift and click to choose whether you want to Run the tests again or Debug them.
You can configure the IDE to trigger tests that were ignored or not started during the previous test run together with failed tests. Click on the Test Runner toolbar and enable the Include Non-Started Tests into Rerun Failed option.
Debug failed tests
If you don't know why a test fails, you can debug it.
In the editor, click the gutter on the line where you want to set a breakpoint.
There are different types of breakpoints that you can use depending on where you want to suspend the program. For more information, refer to Breakpoints.
Right-click the gutter icon next to the failed test and select Debug 'test name'.
The test that has failed will be rerun in the debug mode. After that, the test will be suspended, allowing you to examine its current state.
You can step through the test to analyze its execution in detail.