QtQuickTest Reference DocumentationIntroductionQtQuickTest is a unit test framework for Qt Quick (QML) applications. Test cases are written as JavaScript functions within a TestCase element: import QtQuick 2.0 import QtTest 1.0 TestCase { name: "MathTests" function test_math() { compare(2 + 2, 4, "2 + 2 = 4") } function test_fail() { compare(2 + 2, 5, "2 + 2 = 5") } } Functions whose names start with test_ are treated as test cases to be executed. See the documentation for the TestCase and SignalSpy elements for more information on writing test cases. Running testsTest cases are launched by a C++ harness that consists of the following code: #include <QtQuickTest/quicktest.h>
QUICK_TEST_MAIN(example)
Where "example" is an identifier to use to uniquely identify this set of tests. You should add CONFIG += qmltestcase. for example: TEMPLATE = app TARGET = tst_example CONFIG += warn_on qmltestcase SOURCES += tst_example.cpp The test harness scans the specified source directory recursively for "tst_*.qml" files. If QUICK_TEST_SOURCE_DIR is not defined, then the current directory will be scanned when the harness is run. Other *.qml files may appear for auxillary QML components that are used by the test. The -input command-line option can be set at runtime to run test cases from a different directory. This may be needed to run tests on a target device where the compiled-in directory name refers to a host. For example: tst_example -input /mnt/SDCard/qmltests See tests/qmlauto in the source tree for an example of creating a test harness that uses the QUICK_TEST_SOURCE_DIR macro. If your test case needs QML imports, then you can add them as -import options to the the test program command-line by adding the following line to your .pro file: IMPORTPATH += $$PWD/../imports/my_module1 $$PWD/../imports/my_module2 |