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 \inqmlmodule QtQuick 1
31 \title QtQuickTest Reference Documentation
32 \keyword QtQuickTest Reference Documentation
34 \section1 Introduction
36 QtQuickTest is a unit test framework for Qt Quick (QML) applications.
37 Test cases are written as JavaScript functions within a TestCase
47 function test_math() {
48 compare(2 + 2, 4, "2 + 2 = 4")
51 function test_fail() {
52 compare(2 + 2, 5, "2 + 2 = 5")
57 Functions whose names start with \c{test_} are treated as test cases
58 to be executed. See the documentation for the \l TestCase and
59 \l SignalSpy elements for more information on writing test cases.
61 \section1 Running tests
63 Test cases are launched by a C++ harness that consists of
67 #include <QtQuickTest/quicktest.h>
68 QUICK_TEST_MAIN(example)
71 Where "example" is an identifier to use to uniquely identify
72 this set of tests. You should add \c{CONFIG += qmltestcase}.
78 CONFIG += warn_on qmltestcase
79 SOURCES += tst_example.cpp
82 The test harness scans the specified source directory recursively
83 for "tst_*.qml" files. If \c{QUICK_TEST_SOURCE_DIR} is not defined,
84 then the current directory will be scanned when the harness is run.
85 Other *.qml files may appear for auxillary QML components that are
88 The \c{-input} command-line option can be set at runtime to run
89 test cases from a different directory. This may be needed to run
90 tests on a target device where the compiled-in directory name refers
91 to a host. For example:
94 tst_example -input /mnt/SDCard/qmltests
97 See \c{tests/qmlauto} in the source tree for an example of creating a
98 test harness that uses the \c{QUICK_TEST_SOURCE_DIR} macro.
100 If your test case needs QML imports, then you can add them as
101 \c{-import} options to the the test program command-line by adding
102 the following line to your .pro file:
105 IMPORTPATH += $$PWD/../imports/my_module1 $$PWD/../imports/my_module2
108 \section1 Running tests with QtQuick 1
110 The \c{-qtquick1} option can be passed to a test binary to run
111 the tests using QDeclarativeView (QtQuick 1) rather than QQuickView (QtQuick 2):
114 tst_example -qtquick1
117 To run tests with either QtQuick 1 or QtQuick 2, use
118 "import QtQuick 1.0" in your unit tests and then specify
119 compatibility mode to the QtQuick2 engine:
122 QMLSCENE_IMPORT_NAME=quick1 tst_example