diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-17 18:50:39 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2023-04-18 05:44:55 +0200 |
commit | 9c2ecfc6c06f1defa512e8a8b49d12dd37a313dd (patch) | |
tree | e32ac4309ce43bca02e8c54527598ec8dc2088d9 /src/qmltest | |
parent | 645aaa25b17ad3437e63877576ef7dac7966a934 (diff) |
Document that running a Quick Test always show a window
After 47490648b14938049ddf84c3f665619c1117241c, test functions are
executed asynchronously through a scheduler. This makes the entire logic
for detecting whether a test case completed during setSource() obsolete,
and always results in a window being shown.
That is as such fine, Qt Quick Test always required the GUI and Quick
specific Qt modules and platform plugins to be available (so it wasn't
easily possible to run those tests on a server without any display
infrastructure). But we can now remove the logic from the startup
function.
Add a note to the documentation that running tests always shows a UI,
and how to avoid it using the offscreen platform plugin.
Pick-to: 6.5
Fixes: QTBUG-110592
Change-Id: Ie69b04e3fd4044db2fc7f0fc3ca44947a3dddfce
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmltest')
-rw-r--r-- | src/qmltest/doc/src/qtquicktest-index.qdoc | 4 | ||||
-rw-r--r-- | src/qmltest/quicktest.cpp | 58 |
2 files changed, 30 insertions, 32 deletions
diff --git a/src/qmltest/doc/src/qtquicktest-index.qdoc b/src/qmltest/doc/src/qtquicktest-index.qdoc index d227f44bce..d5534052af 100644 --- a/src/qmltest/doc/src/qtquicktest-index.qdoc +++ b/src/qmltest/doc/src/qtquicktest-index.qdoc @@ -157,6 +157,10 @@ tst_example -help \endcode + \note Running a Qt Quick test case will always show a window on the screen, + even if the test code doesn't involve any Quick UI. To avoid that, run the + test executable with \c {-platform offscreen}. + \section1 Executing C++ Before QML Tests To execute C++ code before any of the QML tests are run, the diff --git a/src/qmltest/quicktest.cpp b/src/qmltest/quicktest.cpp index 0ecb48dd10..c333f7fe1b 100644 --- a/src/qmltest/quicktest.cpp +++ b/src/qmltest/quicktest.cpp @@ -616,39 +616,33 @@ int quick_test_main_with_setup(int argc, char **argv, const char *name, const ch handleCompileErrors(fi, view.errors(), view.engine(), &view); continue; } - if (!QTestRootObject::instance()->hasQuit) { - // If the test already quit, then it was performed - // synchronously during setSource(). Otherwise it is - // an asynchronous test and we need to show the window - // and wait for the first frame to be rendered - // and then wait for quit indication. - view.setFramePosition(QPoint(50, 50)); - if (view.size().isEmpty()) { // Avoid hangs with empty windows. - view.resize(200, 200); - } - view.show(); - if (!QTest::qWaitForWindowExposed(&view)) { - qWarning().nospace() - << "Test '" << QDir::toNativeSeparators(path) << "' window not exposed after show()."; - } - view.requestActivate(); - if (!QTest::qWaitForWindowActive(&view)) { - qWarning().nospace() - << "Test '" << QDir::toNativeSeparators(path) << "' window not active after requestActivate()."; - } - if (view.isExposed()) { - // Defer property update until event loop has started - QTimer::singleShot(0, []() { - QTestRootObject::instance()->setWindowShown(true); - }); - } else { - qWarning().nospace() - << "Test '" << QDir::toNativeSeparators(path) << "' window was never exposed! " - << "If the test case was expecting windowShown, it will hang."; - } - if (!QTestRootObject::instance()->hasQuit && QTestRootObject::instance()->hasTestCase()) - eventLoop.exec(); + + view.setFramePosition(QPoint(50, 50)); + if (view.size().isEmpty()) { // Avoid hangs with empty windows. + view.resize(200, 200); + } + view.show(); + if (!QTest::qWaitForWindowExposed(&view)) { + qWarning().nospace() + << "Test '" << QDir::toNativeSeparators(path) << "' window not exposed after show()."; + } + view.requestActivate(); + if (!QTest::qWaitForWindowActive(&view)) { + qWarning().nospace() + << "Test '" << QDir::toNativeSeparators(path) << "' window not active after requestActivate()."; + } + if (view.isExposed()) { + // Defer property update until event loop has started + QTimer::singleShot(0, []() { + QTestRootObject::instance()->setWindowShown(true); + }); + } else { + qWarning().nospace() + << "Test '" << QDir::toNativeSeparators(path) << "' window was never exposed! " + << "If the test case was expecting windowShown, it will hang."; } + if (!QTestRootObject::instance()->hasQuit && QTestRootObject::instance()->hasTestCase()) + eventLoop.exec(); } if (setup) |