Unit testing

Perform unit testing with ease, as CLion integrates with Google Test, Boost.Test and Catch 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, Boost.Test or Catch 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

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
Test runner

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

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.

Run/Status icons

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