Home |
The QtTest framework, provided by Trolltech, is a tool for unit testing Qt based applications and libraries. QtTest provides all the functionality commonly found in unit testing frameworks as well as extensions for testing graphical user interfaces.
Table of contents:
QtTest is designed to ease the writing of unit tests for Qt based applications and libraries:
Feature | Details |
---|---|
Lightweight | QtTest 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 | QtTest offers functionality for mouse and keyboard simulation. |
IDE friendly | QtTest 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 Trolltech partners.
QtTest integrates itself into your existing Qt installation. In the QtTest directory, invoke qmake and run your build utility (for example make or nmake). After compilation finished, run make install (or nmake install for Visual Studio) to install QtTest. Depending on your installation, the make install step might require super user (root) priviledges.
Note that QtTest evaluates the existing Qt installation and builds a debug and/or release library accordingly. If you reinstall Qt, you should rebuild and reinstall QtTest as well.
This tutorial gives a short introduction to how to use some of the features of the QtTest framework. It is divided into four chapters:
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 testfunctions to be executed. If no testfunctions are passed, all tests are run. If the name of an entry in the test function's test data is appended to the test function's name, the test function will be run only with that testdata.
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 don't exists, 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 by QtTest::exec():
Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Solutions |