Create Qt Quick tests | Qt Creator Documentation

- Qt Creator Documentation
- Create Qt Quick tests
- Qt Creator 19.0.0

Create Google tests ◦ Create Qt tests

# Create Qt Quick tests

Qt Creator integrates the Qt Quick Test unit test framework for Qt Quick applications, where you write test cases as JavaScript functions.

To create a Qt Quick test:

1. Go to File > New Project > Test Project.
2. Select Qt Quick Test Project > Choose.
3. In the Project and Test Information dialog, specify settings for the project and test.

4. In Test case name, enter a name for the test case.
5. Select Generate setup code to execute C++ code before running any of the QML tests. The testing framework will call slots and invocable functions, as described in Executing C++ Before QML Tests.
6. Select Generate initialization and cleanup code to add functions to your test that the testing framework executes to initialize and clean up the test.
7. In Qt code compatibility, select Qt6 and higher or Qt5 and higher to set the Qt version compatibility for the test.
8. In Build system, select the build system to use for building the project: CMake, qmake, or Qbs. To build with CMake when developing with Qt 5 or Qt 6.4 or earlier, select CMake with Qt 5 Compatibility.

Qt Creator creates the test in the specified project directory. Edit the `.cpp` file to add private slots for each test function in your test.

Note: While scanning for tests, the parser takes into account only files that directly or indirectly include QuickTest or its equivalent `QtQuickTest/quicktest.h`. If one gets found, it tries to detect statements to create a Qt Quick test application and if it can find any it will parse respective QML files. If the C++ part will not be built with the current configuration, there will be no automatic scanning of QML files.

Note: If General > Process arguments is enabled, you can execute tests and write one or more additional log files in parallel. Use the output format option `-o filename,format` to do so. Using standard out for `filename` is not supported as Qt Creator is using this output channel.

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

Create Google tests ◦ Create Qt tests