Results 1 to 4 of 4

Thread: How do I unit test a GUI

  1. #1
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How do I unit test a GUI

    I am new to Qt and consider myself fairly new to development having recently returned to the field after many years. I was tasked with learning how to unit test gui fucntions. I have read copied and run the QString example in the tutorial. However, I dont get the overall picture on how to test a function written outside of my test project. I wrote a simple gui that writes to a textlable after a pushbutton click. How do I test this as the code does not reside in my test project. Is there a document or tutorial that gives the overall picture? Think total newbie? Thanks!


    Here is the code for the gui:

    void MainWindow:n_pushButton_clicked()
    {
    ui->label->setText("Hello World");
    }

  2. #2
    Join Date
    Aug 2015
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5

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

    jolema (31st August 2015)

  4. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I unit test a GUI

    Quote Originally Posted by jolema View Post
    I was tasked with learning how to unit test gui fucntions.
    There are different ways of automatically testing UI parts.

    One option is to use the built-in functionality of the Qt unit test framework QTest, see key... and mouse... methods here http://doc.qt.io/qt-5/qtest.html

    Another option is to first run the UI and record events and then replay those.
    Either by doing that yourself, or by using tools designed for that, such as Autopilot-Qt or Squish

    Quote Originally Posted by jolema View Post
    However, I dont get the overall picture on how to test a function written outside of my test project.
    Like for any other unit test, you need to be able to instantiate an object for the class in question.
    Either by building the class into the unit test executable (by adding it to the unit test's .pro file) or by linking with a library that contains the class.

    When using a UI testing tool such as Squish, that is slightly different as it will launch the application and hook into it for getting and setting values, sending events, etc.

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    jolema (31st August 2015)

  6. #4
    Join Date
    Aug 2015
    Posts
    4
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I unit test a GUI

    Quote Originally Posted by anda_skoa View Post
    There are different ways of automatically testing UI parts.

    One option is to use the built-in functionality of the Qt unit test framework QTest, see key... and mouse... methods here http://doc.qt.io/qt-5/qtest.html

    Another option is to first run the UI and record events and then replay those.
    Either by doing that yourself, or by using tools designed for that, such as Autopilot-Qt or Squish


    Like for any other unit test, you need to be able to instantiate an object for the class in question.
    Either by building the class into the unit test executable (by adding it to the unit test's .pro file) or by linking with a library that contains the class.

    When using a UI testing tool such as Squish, that is slightly different as it will launch the application and hook into it for getting and setting values, sending events, etc.

    Cheers,
    _
    This clears things up quite a bit. Thank you.

Similar Threads

  1. Unit Test: Test if QPushButton has a menu
    By FelixB in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2012, 12:12
  2. debugging a unit test
    By Martin Drozdik in forum Newbie
    Replies: 4
    Last Post: 1st June 2012, 01:38
  3. Problem with Qt Unit Test
    By rubikon in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2011, 09:18
  4. Unit test coverage
    By leoalvesmachado in forum Newbie
    Replies: 3
    Last Post: 16th April 2010, 13:48
  5. How to unit test a Qt Gui
    By mitskits in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2006, 07:36

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.