QTestLib Manual
|
Feature | Details |
---|---|
Lightweight | QTestLib consists of about 6000 lines of code and 60 exported symbols. |
Self-contained | QTestLib requires only a few symbols from the Qt Core library for non-gui testing. |
Rapid testing | QTestLib needs no special test-runners; no special registration for tests. |
Data-driven testing | A test can be executed multiple times with different test data. |
Basic GUI testing | QTestLib offers functionality for mouse and keyboard simulation. |
IDE friendly | QTestLib outputs messages that can be interpreted by Visual Studio and KDevelop. |
Thread-safety | The error reporting is thread safe and atomic. |
Type-safety | Extensive use of templates prevent errors introduced by implicit type casting. |
Easily extendable | Custom types can easily be added to the test data and test output. |
Note: For higher-level GUI and application testing needs, please see the Qt testing products provided by Nokia partners.
All public methods are in the QTest namespace. In addition, the QSignalSpy class provides easy introspection for Qt's signals and slots.
To create a test, subclass QObject and add one or more private slots to it. Each private slot is a testfunction in your test. QTest::qExec() can be used to execute all testfunctions in the test object.
In addition, there are four private slots that are not treated as testfunctions. They will be executed by the testing framework and can be used to initialize and clean up either the entire test or the current test function.
If initTestCase() fails, no testfunction will be executed. If init() fails, the following testfunction will not be executed, the test will proceed to the next testfunction.
Example:
class MyFirstTest: public QObject { Q_OBJECT private slots: void initTestCase() { qDebug("called before everything else"); } void myFirstTest() { QVERIFY(1 == 1); } void mySecondTest() { QVERIFY(1 != 2); } void cleanupTestCase() { qDebug("called after myFirstTest and mySecondTest"); } };
For more examples, refer to the QTestLib Tutorial.
If you are using qmake as your build tool, just add the following to your project file:
QT += testlib
If you are using other buildtools, make sure that you add the location of the QTestLib header files to your include path (usually include/QtTest under your Qt installation directory). If you are using a release build of Qt, link your test to the QtTest library. For debug builds, use QtTest_debug.
See Writing a Unit Test for a step by step explanation.
The syntax to execute an autotest takes the following simple form:
testname [options] [testfunctions[:testdata]]...
Substitute testname with the name of your executable. testfunctions can contain names of test functions to be executed. If no testfunctions are passed, all tests are run. If you append the name of an entry in testdata, the test function will be run only with that test data.
For example:
/myTestDirectory$ testQString toUpper
Runs the test function called toUpper with all available test data.
/myTestDirectory$ testQString toUpper toInt:zero
Runs the toUpper test function with all available test data, and the toInt test function with the testdata called zero (if the specified test data doesn't exist, the associated test will fail).
/myTestDirectory$ testMyWidget -vs -eventdelay 500
Runs the testMyWidget function test, outputs every signal emission and waits 500 milliseconds after each simulated mouse/keyboard event.
The following command line arguments are understood:
cetest is a convenience application which helps the user to launch an application remotely on a Windows CE device or emulator.
It needs to be executed after the unit test has been successfully compiled.
Prior to launching, the following files are copied to the device:
The syntax to execute an autotest takes the following simple form:
cetest [options] ...
cetest provides the same options as those for unit-testing on non cross-compiled platforms. See Command Line Arguments for more information.
The following commands are also included:
Note: debug is the default build option.
QtRemote is a small library which is build after QTestLib. It allows the host system to create a process on a remote device and waits until its execution has been finished.
cetest uses Microsoft ActiveSync to establish a remote connection between the host computer and the device. Thus header files and libraries are needed to compile cetest and QtRemote successfully.
Prior to installation of Qt, you need to set your INCLUDE and LIB environment variables properly.
A default installation of Windows Mobile 5 for Pocket PC can be obtained by:
set INCLUDE=C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Activesync\Inc;%INCLUDE% set LIB=C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket PC SDK\Activesync\Lib;%LIB%
Note that Qt will remember the path, so you do not need to set it again after switching the environments for cross-compilation.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt qtextended4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com