Testing GUI structure
In my new project I would like to focus more on TDD for GUI. I know that I can test GUI behaviour, like signal to one button/combobox and observe return signal or other visual changes.
But how about testing structure. I mean - TDD encourage to write failing test first then create minimum code to cover this test.
Currently I tried this:
QLabel* label = test_object->findChild<QLabel*>("class_label"); QLineEdit* edit = test_object->findChild<QLineEdit*>("class_name"); QVERIFY(label != nullptr); QVERIFY(edit != nullptr); QHBoxLayout* parent_layout = test_object->findChild<QHBoxLayout*>("class_name_layout"); QVERIFY(parent_layout != nullptr); QCOMPARE(label->parent(), edit->parent()); QCOMPARE(label->parent(), test_object.get()); QCOMPARE(label->maximumHeight(), 25); QCOMPARE(edit->maximumHeight(), 25); QVERIFY(!edit->hasFrame()); QCOMPARE(edit->maximumHeight(), 25); QVERIFY2(label->x() < edit->x(), qPrintable(QString("Horizontal position of label (%1) should be " "smaller then edit (%2)") .arg(label->x()) .arg(edit->x())));
This raises two questions:
- good object naming convention, as in bigger and nested widgets name need to be unique
- all test for position relation (like label A need to be left of LineEdt B) need to make widget visible (show or setVisibility). This makes test in Docker or other isolated environments little more difficult (like enforce use xvfb or other X emulators).
- or maybe there's other established way of work with GUI and testing. If so - then please share link to this guide.
Hi and welcome to devnet,
Are you trying to test the look and feel of your widget ?
That's the kind of test that are usually conducted with your potential users/customers.
Also you have to take into account that unless you hard code every sizes used in your widget, you'll get different results depending on the platform you run your test on.
When testing a GUI application, you usually don't test the design, you test that the widget reacts as you wish, e.g. that clicking on a button triggers the change of the colour from a QLabel from one to another.