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:

    {Project and Test Information dialog - Catch2 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.

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

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.