Doctest support
Doctest is a single-header framework with self-registering tests.
tip
Learn about the framework specifics in the Doctest section of our Unit Testing Tutorial.
Adding Doctest to your project
Download the latest version of doctest.h and copy it into your project tree.
The minimum supported version is 2.3.0.
Include the header in your test files:
#include "doctest.h"
In only one header file, precede
#include
with#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
.See these instructions if you need to supply your own
main
.
Doctest run/debug configuration
Open the Run | Edit Configurations dialog. Under the Doctest node, you will see the configurations created automatically for the detected targets.
To create a new Doctest configuration, click
and select Doctest from the list of templates.
Specify the configuration settings:
Set the configuration name in the Name field. This name will be shown in the list of the available run/debug configurations.
- Suite/TestTest
Select this option to run a particular test or suite.
In the Suite field, specify the suite name. Start typing, and auto-completion will suggest the available suits:
In the Test field, select the desired test. Leave this field to run the entire suite.
Alternatively, you can leave the Suite and Test fields empty, and provide the Doctest's command line flags via Program arguments instead.
In the Target field, select the desired target from the list.
Save the configuration, and it's ready for Run
or Debug
.
note
Instead of editing a single configuration, you can modify the Doctest template itself. In this case, the settings you specify will apply as defaults to all new configurations of this type.
Running tests
In CLion, there are several ways to start a run/debug session for tests, one of which is using special gutter icons. These icons help quickly run or debug a single test or a whole suite/fixture:

Gutter icons also show test results (when already available): success or failure
.
When you run a test/suite/scenario using gutter icons, CLion creates a temporary Doctest configuration, which is greyed out in the configurations list. To save a temporary configuration, select it in the Edit Configurations dialog and press .
Exploring results
When you run tests, CLion shows the results and the process in the built-in test runner window. This window includes:
progress bar with the percentage of tests executed so far,
tree view of all the running tests with their status and duration,
tests' output stream,
toolbar with the options to rerun failed
tests, export
or open previous results saved automatically
, sort the tests alphabetically
to easily find a particular test, or sort them by duration
to understand which test ran longer than others.
