Catch is a cross-platform test framework, which you can use in CLion. That means you can create Catch test runner configurations that let you specify test names (with wildcards) or tags, see the results of your test runs, hierarchically, in the test runner window, and can re-run failing tests, or the test where the cursor is, with just a single shortcut. You can even run all tests in a source file.
Getting started with Catch
To start using Catch in your projects, follow these simple steps:
- Download the latest version of
Catch is distributed as a single header file, with no external dependencies (beyond the C++03 standard library).
Alternatively, you can clone the whole Catch repository from GitHub. That will also give you the docs, tests, scripts and source files that get used to build the single include. If you do this you’ll find the single header file in the
Include the header in your test files.
In addition, in exactly one source file you’ll also need to precede the
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 Catch documentation page.
Create the test cases. Note that with Catch you don't need to create a "text fixture class", although that is supported too. You can find a lot more useful information about using Catch in our blog post.
Creating Catch test run/debug configuration
To create a Catch test run/debug configuration manually, do the following:
- In the main menu, select Run | Edit Configurations. In the dialog that opens:
Click on the toolbar or press Alt+Insert. Select Catch Test from the list.
- For the new Catch test run/debug configuration:
Specify its name in the Name text box. This name will be shown in the list of the available run/debug configurations.
Select the Tags/Test radio button to run a test for the particular tags or all the tags. Select the Pattern radio button to run all the tests for a particular pattern.
Specify the tag names in the tags text box. Note, that this option is available only when the Tags/Test radio button 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 text box. 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.
Specify common run/debug configuration parameters.
Apply the changes and close the dialog box.