Basic QtTest Lib Example
Article Metadata
Tested with
Devices(s): Emulator / desktop / device
Compatibility
Platform(s): All Qt Supported
Article
Keywords: QtTest
Created: skumar_rao
(26 Nov 2010)
Last edited: hamishwillee
(11 Oct 2012)
Overview
This article shows how to convert string to it uppercase using Qt's QString. We'll start by writing a simple test to verify that the function QString::toupper correctly copy the string and convert it to uppercase.
Class Implementation
testqstring.cpp
Note that
- The test class must inherit from QObject.
- The tests must be declared as "private slots", so that QtTest can automatically recognize and execute them.
- The macro QCOMPARE verifies that the two objects passed as arguments are identical and displays the value of these two objects, which facilitates debugging.
- QCOMPARE macro is quite strict, in way that the objects compared must be the same type. if you pass a argument as QString and another as constant then a compiler error will occur
- The macro QTEST_MAIN generates a main function that runs all the tests that have been reported via "private slots"
For compilation with qmake, just add the .pro for your project:
QT += testlibmore info can be found at http://doc.qt.nokia.com/latest/qtestlib-manual.html
--skumar_rao 17:50, 26 November 2010 (UTC)

