QT gui 单元测试高级部分
需求 qt 如何进行 gui 单元测试高级特性 解决 测试焦点 使用焦点时需要考虑的重要一点是,在小部件上简单地调用 QWidget::setFocus 将不起作用,因为在执行测试期间小部件不可见。我们需要做的是在我们正在测试的 QWidget 上调用静态函数 QApplication::setActiveWindow void TestPanelConcat::TestFocus() { // enables focus and widget events QApplication::setActiveWindow(&panel); // set initial focus panel.mInputA->setFocus(); QVERIFY2(panel.mInputA->hasFocus(), "Input A doesn't have focus"); // write STR1 QTest::keyClicks(QApplication::focusWidget(), STR1); // move focus to next widget QTest::keyClick(&panel, Qt::Key_Tab); QVERIFY2(panel.mInputB->hasFocus(), "Input B doesn't have focus"); // write STR2 QTest::keyClicks(QApplication::focusWidget(), STR2); // move focus to next widget QTest::keyClick(&panel, Qt::Key_Tab); QVERIFY2(panel.mButtonConcat->hasFocus(), "Button CONCAT doesn't have focus"); // press button CONCAT using space QTest::keyClick(QApplication::focusWidget(), Qt::Key_Space); QCOMPARE(panel....