Basic QtTest Lib Example
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.
- 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 += testlib
more info can be found at http://doc.qt.nokia.com/latest/qtestlib-manual.html
--skumar_rao 17:50, 26 November 2010 (UTC)