JComputerScience
JComputerScience

Reputation: 165

Testing GUIs with GoogleTest & QTest

I have a GUI and I want to test the many functionalities of this GUI. The issue is that the sub-widgets are all private members of this main GUI class. How can I test my main GUI when I can't populate any of these sub-widgets since they are private to me in the test class?

For example, I have multiple line edits as fields in the ui object. These line edits are scraped and dumped into a QVariant object type specific to this GUI. I can't populate these edits from my test functions since they are inaccessible due to privacy issues. Therefore, I can't test the QVariant object matches the data supplied by the GUI.

I also can not call any of the QTest functions on specific widgets to trigger events.

For example, I can't call

QTest::mouseClick(testGUI.ui->pushButton1, ...)

because ui is private and pushButton1 would be private whether it was part of the UI or not. Therefore, I can't simulate mouse click events on these buttons either. I also tried to use

QTest::mouseClick(testGUI, ..., ..., ..., QPoint(70, 180));

Where the QPoint is the absolute position of the button with respect to the widget, but even this doesn't trigger the button clicked.

How can I test these widgets when so much of the widget is private and inaccessible to the user?

Upvotes: 0

Views: 1593

Answers (1)

Dzung Nguyen
Dzung Nguyen

Reputation: 71

You can try to create shared library which includes the directory build-xxx-desktop-debug. Then in the test.pro you do the libs.

Hope it works.

Upvotes: 0

Related Questions