CLion 2019.2 Help

Catch2 support

Catch2 is a cross-platform testing framework. CLion supports Catch versions 1.7.2 and later. With dedicated Catch run/debug configurations, you can specify test names with wildcards or tags and then explore the results in the test runner window.

Get started with Catch2

  1. Download the latest version of catch.hpp from the framework repository.

    Catch2 is distributed as a single header file, with no external dependencies (beyond the C++03 standard library).

  2. Include the header in your test files.

  3. In addition, in exactly one source file you’ll also need to precede the #include with either #define CATCH_CONFIG_MAIN or CATCH_CONFIG_RUNNER. The former instructs Catch to define main() for you, and will take care of parsing command line arguments and exit codes. Use the latter identifier if you want to supply your own main(). For more details, refer to Catch2 documentation.

  4. Create the test cases. Note that with Catch2 you don't need to create a "text fixture class", although that is supported too. See this blog post for more information about using Catch2 in CLion.

Create a Catch run/debug configuration

  1. In the main menu, select Run | Edit Configurations, click icons general add svg on the toolbar or press Alt+Insert, and select Catch from the list of templates.

  2. Catch run/debug configuration
    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.

    • Select the Tags/Test option to run a test for the particular tags or all the tags. Select the Pattern option to run all the tests for a particular pattern.

    • Specify tags in the tags fields. This option is available only when the Tags/Test option is selected.

    • Select the desired test from the Test drop down list. Note, that this option is available only when one or more tags have been provided.

    • Specify the pattern name in the Pattern field. Note, that this option is available only when the Pattern radio button is selected.

    • In the Target field, select the desired target from the list of available targets.

  3. Now you can Runartwork studio icons avd run or Debugicons actions startDebugger svg this configuration and explore test results in the test runner window.

Last modified: 22 August 2019

See Also