Using QTestLib in S60
Article Metadata
Tested with
Compatibility
Article
Contents |
Overview
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.
Example
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] = bytes.data(); \
\
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.


(no comments yet)