Running Autotests

Qt Creator integrates the Qt Test framework for unit testing Qt based applications and libraries (commercial only). You can use Qt Creator to build and run autotests for your projects.

To enable the experimental Auto Test plugin, select Help > About Plugins > Utilities > Auto Test. Restart Qt Creator to be able to use the plugin.

Creating Autotests

You can use a wizard to create projects that contain autotests:

  1. Select File > New File or Project > Other Project > Auto Test > Choose to create a project with boilerplate code for an autotest.
  2. In the Project and Test Information dialog, specify settings for the project and autotest:
    1. Select the GUI Application check box to create a Qt application.
    2. In the Test case name field, enter a name for the test case.
    3. Select the Requires QApplication check box to add the include statement for QApplication to the main.cpp file of the project.
    4. Select the Generate initialization and cleanup code checkbox to add functions to your test that are executed by the testing framework to initialize and clean up the test.
    5. In the Build auto tests field, select Always to always build the autotest when building the project or Debug Only to only build it during debug builds.

Qt Creator creates the autotest in the tests\auto directory in the project directory. Edit the .cpp file to add private slots for each test function in your test. For more information about creating autotests, see Creating a Test.

Building and Running Autotests

To build and run autotests:

  1. Open a project that contains autotests.
  2. In the Test Results output pane, select (Run All Tests) to run all test or (Run Selected Tests) to run the selected tests.

    You can select the tests to run in the Tests view in the Projects pane. For more information, see Viewing Tests.

    Note: By default, Qt Creator builds a project before deploying and running it.

If a test takes more than a minute to execute, the default timeout might stop the test execution. To increase the timeout, select Tools > Options > Test Settings.

The code inside a benchmark test is measured, and possibly also repeated several times in order to get an accurate measurement. This depends on the measurement back-end that you can select in Test Settings: walltime, CPU tick counter, event counter, Vallgrind Callgring, and Linux Perf. For more information, see Creating a Benchmark.

Viewing Test Output

The test results are displayed in the Test Results output pane.

ResultDescription
BENCHBenchmark test.
BFAILBlacklisted test case failed. Since Qt 5.4, you can provide a BLACKLIST file for tests. It is mainly used internally by the Qt CI system.
BPASSBlacklisted test case passed.
DEBUGDebug message.
XFAILTest case is expected to fail, so it is marked by using the QEXPECT_FAIL macro. If the test case passes instead, an unexpected pass (XPASS) is written to the test log.
FAILTest case failed. Double-click the line for more information.
INTERNALInternal message.
PASSTest case passed.
SKIPTest case was skipped.
XPASSTest case passed even though it was expected to fail.
WARNWarning message.

To view only messages of a particular type, select (Filter Test Results), and then select the types of messages to show.

To hide internal messages and run configuration warnings, select Tools > Options > Test Settings.

© 2015 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.