Create Catch2 tests | Qt Creator Documentation

- Qt Creator Documentation
- Create Catch2 tests
- Qt Creator 17.0.1

How To

# Create Catch2 tests

To build and run Catch2 tests, you can either install Catch2 libraries and headers or use the single include header file in the Catch2 repository.

If the compiler and build system can find the Catch2 headers automatically, you do not need to specify the include directory when creating the test.

To create a basic Catch2 test:

1. Go to File > New Project > Test Project.
2. Select Catch2 Test Project > Choose to create a project with boilerplate code for a Catch2 test.
3. In the Project and Test Information dialog, specify settings for the project and test:

   1. In Test framework, select Catch2 v3 (shared libraries) to link against Catch2 (recommended for version 3), or Catch2 v2 (header only) to use a single header include (recommended for version 2).
   2. In Test case name, specify a name for the test case file.
   3. In Catch2 install directory (optional), you can enter a path to the directory that has the Catch2 header files.
   4. Select Use own main to use a self-defined main function.
   5. Select Use Qt libraries set up the project to use Qt features.
   6. In Build system, select the build system to use for building the project: CMake, qmake, or Qbs.

Qt Creator creates the test in the project directory.

For more information about creating Catch2 tests, see Catch2.

Note: While scanning for tests, the parser takes into account only files that directly or indirectly include one of the common Catch2 headers (`catch2.hpp`, `catch_all.hpp`, and some more). Files that currently will not be built will be ignored.

See also How To: Test, Select the build system, Testing, and Test Results.

How To