I am trying to unit test (using Qt Test) the individual widgets in a Qt Widgets application, like menuBar, pushButton, etc. The project has been set up as a Subdirs project, where the both the Qt application and GUI test sub projects have their own directory and .pro file. The problem is that I cannot access any widget residing in MainWindow from the test class (MainWindowTest), as the compiler says:
- error: cannot cast 'MainWindow' to its private base class 'Ui_MainWindow'
- 'pushButton' is a private member of 'Ui_MainWindow'
- constrained by private inheritance here
I tried to declare the MainWindowTest a friend in MainWindow, but it didn't help. I also tried to forward declare MainWindowTest in a separate header and then include it in mainwindow.h (a still declare MainWindowTest as friend), but that didn't help either.
Just creating a default subdir Widget application and a GuiTest AutoTest subdir project in Creator will produce all necessary code for this.
What I'm actually trying to achieve here, is to make a MainWindow instance in the private area of MainWindowTest and then write a couple of unit tests to check for the existence of the widgets and then do some keyboard and mouse event based testing. But, because I cannot even have access to the widgets, it would be terribly hard to do so.
I already looked through a couple of "solutions" over the net, but none of them seem to be clean solutions. I'd like to be able to execute QVERIFY2(win.pushButton, "pushButton wasn't created.") sort of thing right now, but as I have said, pushButton is inaccessible.