PDA

View Full Version : How to write automated tests for my app?



oficjalne100
11th March 2012, 14:42
Hello

I have custom Application class (QApplication descendant) which is the core of my app (it handle application states and create windows when needed). And I want to write automated tests for my app (to ensure quality). I found that page:
http://qt.nokia.com/learning/online/talks/developerdays2010/tech-talks/introduction-to-automated-testing-for-qt-applications/
And I recognize that in order to test my app I should make it as shared library (or maybe few shared libraries).
But mentioned page apparently assume that default QApplication is used. So I have question:
How I should manage my own custom QApplication descendant in the test suit?
Maybe I should create my QApplication object but not call exec() function?
Will that work?

thanx
Szyk

wysota
11th March 2012, 15:13
The first thing to mention is to define what you want to test as "testing" is a very broad term.

oficjalne100
11th March 2012, 19:33
Ritght!
I want write test to perform about 20 typical user actions. (typical "positive" use cases). This will be purely GUI simulation.
One of that tests should be done like that: (open login window), type username, type passowrd, click Ok, (connection in the background)(close login window)(open main window), type some text, push enter, click icon (open related window), click some icon (in related window), click close button (close related window), push enter, hit alt+f4 (close main window).
Then next similar test should be performed.

wysota
11th March 2012, 20:46
Ritght!
I want write test to perform about 20 typical user actions. (typical "positive" use cases). This will be purely GUI simulation.
One of that tests should be done like that: (open login window), type username, type passowrd, click Ok, (connection in the background)(close login window)(open main window), type some text, push enter, click icon (open related window), click some icon (in related window), click close button (close related window), push enter, hit alt+f4 (close main window).
Then next similar test should be performed.

QtTestLib is not great at things like that. It's more suited to unit-testing.

oficjalne100
13th March 2012, 07:06
Ok! I try to write some automated tests "positive use cases" of my application. And it almost works (I have problem with main menu simulated clicks, but probably it is not related to whole "positive use cases" tests concept). I do it as follow:
1. Write test object - it should create QApplication (or its descendant) in initTestCase() and delete them in cleanupTestCase(), other slots should perform tests (as usual in QTestLib)
1. Detect "--demo" parameter in main(), and remove it from parameters list (or create QStringList with all parameters except "--demo") to avoid fatal error in QTest::qExec
2. Create in main() test object (e.g. called lTest)
3. Call in main(): return QTest::qExec(&lTest, lParams); In that case lParams is mentioned QStringList with main() parameters (except "--demo") converted from plain asci to QString.