Results 1 to 2 of 2

Thread: Testing QApplication descendant with QTestLib

  1. #1
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Testing QApplication descendant with QTestLib

    Hello,

    I'm trying to figure out how to use QTestLib with custom QApplication. So, I want to test if my command line aruments are handled correctly, for example language is set to the specified one (i.e. --set-lang=de). All the logic is placed in Application::exec().

    So, the question is how to run Application::exec() from my test. Then I'd like to create MainWindow and access any label within it to test its text.

    Thanks.
    Last edited by Oleg; 5th April 2012 at 14:09. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Testing QApplication descendant with QTestLib

    If you want to test the languages, you don't need to access any labels. All you need to do is to call tr() passing it a message id and context and check if the result is translated properly. Parsing the command line should be done before calling exec as exec() is a blocking call so it will not be possible to test anything within it. Remember QTestLib is about black-box testing so you can't test anything that doesn't provide some kind of result. Of course it is technically possible to do what you want however you'd be rewriting some of QTestLib functionality:

    Qt Code:
    1. void TestClass::testobject() { QTest::qExec(this); }
    2.  
    3. int main(int argc, char **argv) {
    4. MyApp app(argc, argv);
    5. TestClass testobject;
    6. QMetaObject::invokeMethod(&testobject, "startTest", Qt::QueuedConnection);
    7. app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Oleg (5th April 2012)

Similar Threads

  1. Testing Qt-Software with a GUI Testing Tool
    By nightghost in forum Qt Programming
    Replies: 8
    Last Post: 22nd February 2012, 07:43
  2. Replies: 2
    Last Post: 1st August 2011, 06:30
  3. Cruise Control and QtTestLib?
    By gfunk in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2007, 19:16
  4. GUI Testing
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2007, 13:46
  5. <QtGui/QApplication> vs. <QApplication>
    By seneca in forum Qt Programming
    Replies: 5
    Last Post: 25th January 2006, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.