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
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
#define QTEST_MAIN_S60(TestObject) \
int main(int argc, char *argv) \
char *new_argv; \
QApplication app(argc, argv); \
QString str = "C:\\data\\" + QFileInfo(QCoreApplication::applicationFilePath()).baseName() + ".log"; \
QByteArray bytes = str.toAscii(); \
char arg1 = "-o"; \
new_argv = argv; \
new_argv = arg1; \
new_argv = 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.