CLion 2018.3 Help

Run, Rerun, and Debug Tests

Generally, CLion runs and debugs tests in the same way as other applications, by running the Run/debug configurations you have created. When doing so, it passes the specified test classes or methods to the test runner.

In many cases, you can initiate a testing session from a context menu. For this purpose, the Run and Debug commands are provided in certain context menus. For example, these commands are available for a test class, directory, or a package in the Project Tool Window. They are also available for a test class or method you are currently working on in the editor.

The tests run in the background, so you can execute several tests at the same time.

Each running configuration gets its own tab in the Run tool window (the Test Results tab). One tab can aggregate several tests.

Run or debug a test

To start running or debugging a test, you can use the main toolbar, or a context menu in the Project tool window or in the editor:

  • Using the main toolbar:
    1. Select the necessary run/debug configuration from the list on the main toolbar.

    2. Click Run Run or Debug Debug to the right of the list. (Alternatively, go to Run | Run (Shift+F10) or Run | Debug (Shift+F9) on the main menu.)

  • Using a context menu:

    Right-click a test class in the Project tool window, or open it in the editor, and right-click the background. On the context menu, choose Run < class name> or Debug....

  • To run/debug a unit test, you can also use the gutter icons. Click run 2x gutter icon to run a single test, or run run 2x icon to run all tests from the suit (fixture, in case of Google Test):

    cl runTestGutter
    Note: following the first run of a test, the gutter icons indicate the test state: success (icon testsuccess 2x icon) or failed (icon testfailed2 2x icon), as in below example:
    cl failedTestGutter

You can repeat your test session, or individual tests without leaving your test runner tab of the Run tool window. The tests are performed again using the same run configuration as in the initial run.

Rerun a testing session

  • Press Ctrl+F5 or click icons toolwindows toolWindowRun svg on the toolbar of the Test Runner tab.

Rerun an individual test

  • In the Test Runner tab, click a test case node or a test and select Run <test target> on its context menu.

Rerun failed tests

  • In the Test Runner tab, click Rerun Failed Tests button on the toolbar.

Debug a failed test

  1. In the Test Runner tab, press Shift and click Rerun Failed Tests icons runConfigurations rerunFailedTests svg.

  2. Select Debug from the Restart Failed Tests popup.

    The tests that have failed will rerun in the debug mode.

Last modified: 14 February 2019

See Also

Reference: