gui-qml icon indicating copy to clipboard operation
gui-qml copied to clipboard

Create QML test automation target (qml/test/test_bitcoin-qt)

Open johnny9 opened this issue 2 years ago • 17 comments

Adds src/qml/test/test_bitcoin-qt as a new test target. This program is built using the QuickTest library. It can be used to validate our qml code by rederimg our components and providing simulated user input. It is set to only be built if QuickTest library is found, gui tests are enabled, and bitcoin-qt is configured for qml.

As a part of test setup, a test implementation of our imageprovider is added to the test target to avoid bringing in too many dependencies. Additionally, a fake AppMode component is added to mock setting the device layout mode.

More information about the QuickTest library can be found at https://doc.qt.io/qt-5.15/qtquicktest-index.html.

Windows Intel macOS Apple Silicon macOS ARM64 Android

johnny9 avatar Jan 13 '23 01:01 johnny9

@johnny9

Thank you very much for working on tests!

Mind adding some words to the PR description?

hebasto avatar Jan 14 '23 11:01 hebasto

tst_*.qml is actually the pattern the library uses to find test cases in a directory.

johnny9 avatar Jan 14 '23 11:01 johnny9

Still have some linking issues with Makefile.qmltest.include it seems as CI isn't happy. I likely linked too make things into the binary.

johnny9 avatar Jan 14 '23 12:01 johnny9

Still have some linking issues with Makefile.qmltest.include it seems as CI isn't happy. I likely linked too make things into the binary.

Looking into them...

hebasto avatar Jan 14 '23 12:01 hebasto

Static builds, which all builds with depends are, require importing of plugins like this:

--- a/src/qml/test/onboardingtests.cpp
+++ b/src/qml/test/onboardingtests.cpp
@@ -1,11 +1,32 @@
 // Copyright (c) 2023 The Bitcoin Core developers
 // Distributed under the MIT software license, see the accompanying
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <qml/test/onboardingtests.h>
+
+#if defined(HAVE_CONFIG_H)
+#include <config/bitcoin-config.h>
+#endif
+
 #include <QtQuickTest>
 #include <QQmlEngine>
 #include <QQmlContext>
 #include <qml/test/testimageprovider.h>
-#include <qml/test/onboardingtests.h>
+
+#if defined(QT_STATICPLUGIN)
+#include <QtPlugin>
+Q_IMPORT_PLUGIN(QtQuick2Plugin)
+Q_IMPORT_PLUGIN(QTestQmlModule)
+#if defined(QT_QPA_PLATFORM_XCB)
+Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
+#elif defined(QT_QPA_PLATFORM_WINDOWS)
+Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin);
+#elif defined(QT_QPA_PLATFORM_COCOA)
+Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin);
+#elif defined(QT_QPA_PLATFORM_ANDROID)
+Q_IMPORT_PLUGIN(QAndroidPlatformIntegrationPlugin)
+#endif
+#endif
 
 Setup::Setup()
 {

And add to build-aux/m4/bitcoin_qt.m4 a few lines QT_LIBS="$QT_LIBS -L$qt_plugin_path/../qml/QtTest" and _BITCOIN_QT_CHECK_STATIC_PLUGIN([QTestQmlModule], [-lqmltestplugin]) (did not test yet).

hebasto avatar Jan 14 '23 13:01 hebasto

Maybe, label this PR as a draft for now?

hebasto avatar Jan 14 '23 13:01 hebasto

FWIW, I'm testing this PR on Ubuntu 22.04 with depends:

$ make -C depends NO_WALLET=1 NO_ZMQ=1 NO_UPNP=1 NO_NATPMP=1 NO_QR=1
$ ./autogen.sh
$ ./configure --disable-fuzz-binary --disable-bench CONFIG_SITE=$PWD/depends/x86_64-pc-linux-gnu/share/config.site
$ make clean
$ make

hebasto avatar Jan 14 '23 14:01 hebasto

From https://doc.qt.io/qt-5/qtquicktest-index.html:

Note: There is no binary compatibility guarantee for the Qt Quick Test module. This means that an application that uses Qt Quick Test is only guaranteed to work with the Qt version it was developed against. However, source compatibility is guaranteed.

Should we skip Quick test when building with depends?

hebasto avatar Jan 14 '23 14:01 hebasto

Thank you for the review Hebasto. Very helpful. Marked as a draft and will unmark after addressing the issues you've mentioned and am more confident it can get through CI.

johnny9 avatar Jan 14 '23 16:01 johnny9

@johnny9

Here is a quick and dirty branch which is built successfully in all CI tasks. However, running qml/test/test_bitcoin-qt in the CI environment needs more investigation regarding which value of the QT_QPA_PLATFORM variable should be used.

Feel free to use my branch at your discretion.

hebasto avatar Jan 15 '23 14:01 hebasto

@johnny9

Here is a quick and dirty branch which is built successfully in all CI tasks. However, running qml/test/test_bitcoin-qt in the CI environment needs more investigation regarding which value of the QT_QPA_PLATFORM variable should be used.

Feel free to use my branch at your discretion.

Thank you. I'll take a look at it and merge it with my branch. I made an attempt last night but struggled with the QT STATIC PLUGIN checks. I'll be investigating how to get this supported in cirrus afterwards. I have some ideas but it'll depend on what kind of platform support they have for a buffer to render into. I'd like to use this to validate the qml in our PRs and maybe even generate screenshots since that eats up a lot of review time.

johnny9 avatar Jan 15 '23 14:01 johnny9

I made an attempt last night but struggled with the QT STATIC PLUGIN checks.

Still thinking it doesn't worth. See https://github.com/bitcoin-core/gui-qml/pull/215#issuecomment-1382813668.

hebasto avatar Jan 15 '23 14:01 hebasto

The qml/pages/onboarding/OnboardingWizard.qml is still to be added to QML_RES_QML.

hebasto avatar Jan 16 '23 13:01 hebasto

Might the introducing of src/qml/pages/onboarding/OnboardingWizard.qml be split up into its own PR?

hebasto avatar Jan 20 '23 10:01 hebasto

Might the introducing of src/qml/pages/onboarding/OnboardingWizard.qml be split up into its own PR?

Yeah I can do that. It was done to simplify testing but the change is generally good as the main,qml gets simpler.

johnny9 avatar Jan 20 '23 13:01 johnny9

Update from 75da2a2 to ed8222b

  • Rebased with main

johnny9 avatar Sep 01 '23 00:09 johnny9

Need to cleanup the commit history :D

jarolrod avatar Sep 08 '23 07:09 jarolrod