Unit testing

Perform unit testing with ease, as CLion integrates with Google Test, Catch, Boost.Test and Doctest frameworks.

Run tests

There is a default way to run tests by simply running a regular executable in CLion. However to benefit from a built-in test runner, use special Google Test, Catch, Boost.Test, or Doctest configuration.

Running tests

In case your CMake target is linked with gtest or gmock, this configuration will be created automatically. Or you can alternatively run a single test, fixture or whole file by pressing ⌃⇧R. In addition, you can create and update such configurations manually in Run | Edit Configurations... settings:

Running tests

To narrow the set of tests in case of Catch configuration, use tags and benefit from the tag names completion:

Catch config

Test runner

Inspect results

Get the best of test-driven development with an easy-to-use and fluent unit test runner. Its dedicated view will show you:

  • the progress bar with the percentage of tests executed so far,
  • a tree view of all the tests running, including the information about test status and test duration,
  • the whole test output stream, and more

Besides, CLion's test runner allows you:

  • to rerun any test, all tests or all failed tests,
  • export test results and open previous results from the history, saved automatically,
  • navigate to the source code of a particular test via Ctrl+↓
Run/Status icons

Run/Status icons

Icons in the left gutter allow you to run/debug tests or run them with Valgrind Memcheck, as well as report the status of the tests: success or failure.

Generate code

Code generation feature (Alt+Insert) can help a lot while writing unit tests. For Google Test create test, test fixture or SetUp/TearDown Methods.

Code generation in tests

In case of generating test for fixtures, TEST() macro is automatically converted to the appropriate TEST_F(), TEST_P(), TYPED_TEST(), or TYPED_TEST_P():

Code generation in tests
CTest support

CTest support

CTest, a CMake-specific test runner, is supported in CLion. This means the list of tests that are run with CTest is detected, and the IDE automatically creates run/debug configurations for them. When tests are launched, the results are presented in the built-in test runner, from which you can debug tests, rerun only failed tests, and much more.