Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Using QTestLib in S60

From Wiki
Jump to: navigation, search

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic, N97
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Keywords: QTestLib
Created: juhanak (11 Sep 2009)
Last edited: hamishwillee (11 Oct 2012)



This article demonstrates how to use QTestLib for unit testing functionality a Qt based application. QTestLib is designed to read test parameters from console and it also prints test results to console by default

In general passing console parameters for application can be considered inconvenient in S60 especially when testing on device. This snippet demonstrates how to modify QTEST_MAIN macro so that application ignores command line parameters and saves test results to "c:\data" + [application name] +."log" file. This speeds testing process because user can start tests simply clicking on the application icon and tests results will be available under data folder.


Header that defines new macro

#include <QtTest/QtTest>
#ifndef S60UNITTEST_H_
#define S60UNITTEST_H_
#define QTEST_MAIN_S60(TestObject) \
int main(int argc, char *argv[]) \
{ \
char *new_argv[3]; \
QApplication app(argc, argv); \
QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log"; \
QByteArray bytes = str.toAscii(); \
char arg1[] = "-o"; \
new_argv[0] = argv[0]; \
new_argv[1] = arg1; \
new_argv[2] =; \
TestObject tc; \
return QTest::qExec(&tc, 3, new_argv); \

#endif /* S60UNITTEST_H_ */

In cpp file instead of using QTEST_MAIN macro use QTEST_MAIN_S60. Unit test examples for QTestLib can be found under qt\examples\qtestlib folder at Qt SDK.

See also

This page was last modified on 11 October 2012, at 01:18.
31 page views in the last 30 days.