Home · All Classes · Main Classes · Grouped Classes · Modules · Functions

QTestLib Manual

The QTestLib framework, provided by Trolltech, is a tool for unit testing Qt based applications and libraries. QTestLib provides all the functionality commonly found in unit testing frameworks as well as extensions for testing graphical user interfaces.

Table of contents:

QTestLib Features

QTestLib is designed to ease the writing of unit tests for Qt based applications and libraries:

FeatureDetails
LightweightQTestLib consists of about 6000 lines of code and 60 exported symbols.
Self-containedQTestLib requires only a few symbols from the Qt Core library for non-gui testing.
Rapid testingQTestLib needs no special test-runners; no special registration for tests.
Data-driven testingA test can be executed multiple times with different test data.
Basic GUI testingQTestLib offers functionality for mouse and keyboard simulation.
IDE friendlyQTestLib outputs messages that can be interpreted by Visual Studio and KDevelop.
Thread-safetyThe error reporting is thread safe and atomic.
Type-safetyExtensive use of templates prevent errors introduced by implicit type casting.
Easily extendableCustom 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.

QTestLib API

All public methods are in the QTest namespace. In addition, the QSignalSpy class provides easy introspection for Qt's signals and slots.

QTestLib Tutorial

This tutorial gives a short introduction to how to use some of the features of the QTestLib framework. It is divided into four chapters:

  1. Writing a Unit Test
  2. Data Driven Testing
  3. Simulating GUI Events
  4. Replaying GUI Events

Building a Test

If you are using qmake as your build tool, just add the following to your project file:

    CONFIG += qtestlib

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.

QTestLib Command Line Arguments

Syntax

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 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.

Options

The following command line arguments are understood:


Copyright © 2005 Trolltech Trademarks
Qt 4.1.0
Hosted by uCoz