1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the documentation of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:FDL$
10 ** GNU Free Documentation License
11 ** Alternatively, this file may be used under the terms of the GNU Free
12 ** Documentation License version 1.3 as published by the Free Software
13 ** Foundation and appearing in the file included in the packaging of
17 ** Alternatively, this file may be used in accordance with the terms
18 ** and conditions contained in a signed written agreement between you
26 ****************************************************************************/
30 \title QtQuickTest Reference Documentation
31 \keyword QtQuickTest Reference Documentation
33 \section1 Introduction
35 QtQuickTest is a unit test framework for Qt Quick (QML) applications.
36 Test cases are written as JavaScript functions within a TestCase
46 function test_math() {
47 compare(2 + 2, 4, "2 + 2 = 4")
50 function test_fail() {
51 compare(2 + 2, 5, "2 + 2 = 5")
56 Functions whose names start with \c{test_} are treated as test cases
57 to be executed. See the documentation for the \l TestCase and
58 \l SignalSpy elements for more information on writing test cases.
60 \section1 Running tests
62 Test cases are launched by a C++ harness that consists of
66 #include <QtQuickTest/quicktest.h>
67 QUICK_TEST_MAIN(example)
70 Where "example" is an identifier to use to uniquely identify
71 this set of tests. You should add \c{CONFIG += qmltestcase}.
77 CONFIG += warn_on qmltestcase
78 SOURCES += tst_example.cpp
81 The test harness scans the specified source directory recursively
82 for "tst_*.qml" files. If \c{QUICK_TEST_SOURCE_DIR} is not defined,
83 then the current directory will be scanned when the harness is run.
84 Other *.qml files may appear for auxillary QML components that are
87 The \c{-input} command-line option can be set at runtime to run
88 test cases from a different directory. This may be needed to run
89 tests on a target device where the compiled-in directory name refers
90 to a host. For example:
93 tst_example -input /mnt/SDCard/qmltests
96 See \c{tests/qmlauto} in the source tree for an example of creating a
97 test harness that uses the \c{QUICK_TEST_SOURCE_DIR} macro.
99 If your test case needs QML imports, then you can add them as
100 \c{-import} options to the the test program command-line by adding
101 the following line to your .pro file:
104 IMPORTPATH += $$PWD/../imports/my_module1 $$PWD/../imports/my_module2
107 \section1 Running tests with QtQuick 1
109 The \c{-qtquick1} option can be passed to a test binary to run
110 the tests using QDeclarativeView (QtQuick 1) rather than QSGView (QtQuick 2):
113 tst_example -qtquick1
116 To run tests with either QtQuick 1 or QtQuick 2, use
117 "import QtQuick 1.0" in your unit tests and then specify
118 compatibility mode to the QtQuick2 engine:
121 QMLSCENE_IMPORT_NAME=quick1 tst_example