Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The most common way to write testing code is to organize it in a unit-based framework. Qt 4 introduced the QTestLib framework of helper-macros and test runners to facilitate the writing of unit tests for applications and libraries that use Qt. All public methods in this framework are in the QTest namespace. The next examples use this framework.
A Test Class is a class derived from QObject, with some private slots for one or more test functions. A test case is a sequence of test functions to be executed. Each test case must be in its own project with a source module that contains a QTEST_MAIN() macro. QTEST_MAIN() specifies which class is the entry point of this test. It expands to a main() function that creates an instance and executes its private slots in order of declaration. Additional methods for initialization and cleanup can be supplied, initTestCase() and cleanupTestCase() respectively, which get called at the begining and end of the test case.