3

I am new to Qt and unit testing. I have gone through the documentation and example of unit testing, but i couldnt figure out how to use the test scenario's in an application.

For eg. In the documentation a QLineEdit is created and then the value is checked with a specific value.

void testGUI()
{
   QLineEdit lineEdit;
   QTest::keyClicks(&lineEdit, "Hello");
   QCOMPARE(lineEdit.text(),QString("Hello"));
}

When i run the program all the result is shown in the console.

But how can i check if i have a QLineEdit and a QPushButton in a QMainWindow form.

How to do GUI Testing ?

ismail
  • 46,010
  • 9
  • 86
  • 95
SAM
  • 365
  • 1
  • 4
  • 10
  • Have you looked into : http://www.froglogic.com/squish/gui-testing/ – Atif Mar 08 '16 at 21:05
  • I have same issue. I don't know how Qt test can be used with my own app. I went through several tutorials but have no idea how to use it with my own application. I'm not targeting UI I want to know how to test my application using Qt test. – Hareen Laks Oct 05 '19 at 03:50

2 Answers2

3

You seem to be looking into GUI unit-testing.

Here you go: How can I unit test a GUI?

Community
  • 1
  • 1
aayoubi
  • 11,285
  • 3
  • 22
  • 20
  • I have gone throught "The Humble dialog box" documentation. i have also gone throught the documentation provided in Foundation Of Qt book and also the tutorial by Harald Fernengel. But stil i am confused about how to use Unit tesing in qt framework on widgets or in a GUI application. Like suppose that i have a QLineEdit and i want to check at the runtime that the word count is between 3 to 15. How to check with multiple test data? – SAM Jan 17 '12 at 07:40
0

Unit testing usually doesn't include the user interface. Unit testing should be the low level, testing of each unit (class/component). Then integration testing tests the units working together to accomplish something. Sometimes mock objects are employed here to act as stand ins for other components, so verify the behaviour is what you'd expect.

After you have unit testing and integration testing handled, the UI testing should be pretty strait forward. For a Qt project, the cross platform gui testing framework from froglogic called squish might be your best bet. However it is a paid product, and if you don't need its cross platform nature, you may be able to get away with some free tools. Most come down to running your application under some sort of instrumentation, and then it replaying your interactions with the user interface, and verifying the values of text fields etc.

Anyway I believe XCode and Visual Studio provide some basic ui unit testing tools. Their is also a wikipedia article here.

Atif
  • 1,438
  • 16
  • 25