PDA

View Full Version : How do I unit test a GUI



jolema
28th August 2015, 19:59
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::on_pushButton_clicked()
{
ui->label->setText("Hello World");
}

LOC_
28th August 2015, 20:22
My eng,is low,but maybe try watch this series :

https://www.youtube.com/playlist?list=PL2D1942A4688E9D63
https://www.youtube.com/watch?v=8opfd5aYkq8&list=PLS1QulWo1RIZjrD_OLju84cUaUlLRe5jQ
https://www.youtube.com/watch?v=8ntEQpg7gck&list=PLMgDVIa0Pg8WrI9WmZR09xAbfXyfkqKWy

anda_skoa
29th August 2015, 12:56
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 (https://launchpad.net/autopilot-qt) or Squish (http://www.froglogic.com/squish/gui-testing/editions/qt.php)



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,
_

jolema
31st August 2015, 13:47
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 (https://launchpad.net/autopilot-qt) or Squish (http://www.froglogic.com/squish/gui-testing/editions/qt.php)


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.