The use case is, I have a Qt app, and I would like to automate user-style testing of it; that is, I'd like to use keyClicks(), mouseClick(), and so on, but I would like for the Qt application window to actually be displayed while this is happening.
The issue I'm having right now is that using QTestLib involves using the QTEST_MAIN macro instead of defining main myself, so I never get an opportunity to show() the widgets being tested. So, another way to word this question is, is there a way to use QTestLib on an application that is using its main function?
I know Squish and probably Testability Driver are capable of this, but if it is possible to get this functionality without using extra tools, then that would be ideal.
In the Test framework field, select Qt Test or Qt Quick Test. For a Qt test, select the GUI Application check box to create a Qt application. In the Test case name field, enter a name for the test case. For a Qt test, select the Requires QApplication check box to add the include statement for QApplication to the main.
Qt Test is a framework for unit testing Qt based applications and libraries. Qt Test provides all the functionality commonly found in unit testing frameworks as well as extensions for testing graphical user interfaces. Qt Test consists of about 6000 lines of code and 60 exported symbols.
From Qt Wiki. Squish is a tool developed by The Qt Company used for automatic testing of Qt applications.
Figured out how to do this. Makes Squish totally unnecessary, but it requires source code access.
In your test class, store a pointer to the QApplication and any widgets you want to test. For ease of use, store a pointer to your application's QMainWindow. Then, either instantiate your test class with pointers to the widgets you plan on testing, or use window->findChild() to grab any element you need. Keep in mind that you will need to call app->processEvents() after everything. Call it after showing the widget so that all of the child widgets appear. Call it after interacting with a widget so that the interaction is actually processed on the GUI. If you need things to be slow enough to watch, use QTest::qSleep().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With