Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    Unsolved QBS autotestrunner with qtquick test?

    QML and Qt Quick
    1
    2
    386
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      vivi last edited by

      Hi All,

      Is it possible to use the qbs autotestrunner (https://doc-snapshots.qt.io/qbs/qml-qbsconvenienceitems-autotestrunner.html) with qtquick test?

      I can successfuly use it with qtest for the c++ part but cannot figure out how to use it for the qml one.

      Thanks

      1 Reply Last reply Reply Quote 0
      • V
        vivi last edited by vivi


        file: project.qbs

        import qbs
        
        Project {
            references: [
                "autotest-cpp/autotest-cpp.qbs",
                "autotest-qml/autotest-qml.qbs",
            ]
        
            AutotestRunner {
                Depends {
                    name: 'Qt.core'
                }
                environment: [ 'PATH=' + Qt.core.binPath ]
            }
        }
        

        file: autotest-cpp/autotest-cpp.qbs

        import qbs
        
        Product {
            name: 'ut-cpp'
            type: [ 'application', 'autotest' ]
        
            Depends {
                name: 'Qt'
                submodules: [
                    'testlib',
                ]
            }
        
            Group {
                fileTagsFilter: "application"
                qbs.install: true
            }
        
            Group {
                name: 'C++ source files'
                prefix: './'
                files: [
                    "ut-cpp.cpp",
                    "ut-cpp.h",
                ]
            }
        }
        

        file: autotest-cpp/ut-cpp.h

        #ifndef UTCPP_H
        #define UTCPP_H
        
        #include <QObject>
        #include <QtTest/QtTest>
        
        class ut_cpp : public QObject {
            Q_OBJECT
        private slots:
            void test();
        };
        
        #endif // UTCPP_H
        

        file: autotest-cpp/ut-cpp.cpp

        #include "ut-cpp.h"
        
        void ut_cpp::test() { QCOMPARE(1, 1); }
        
        int main(int argc, char *argv[]) {
          QCoreApplication a(argc, argv);
          ut_cpp test;
          return QTest::qExec(&test, argc, argv);
        }
        

        file: autotest-qml/autotest-qml.qbs

        import qbs
        
        Product {
            name: 'ut-qml'
            type: [ 'application', 'autotest' ]
        
            Depends {
                name: 'Qt'
                submodules: [
                    "qmltest",
                ]
            }
        
            Group {
                fileTagsFilter: "application"
                qbs.install: true
            }
        
            Group {
                name: 'C++ source files'
                prefix: './'
                files: [
                    "main.cpp",
                ]
            }
        
            Group {
                name: 'QML files'
                prefix: './'
                qbs.install: true
                qbs.installDir: "."
                files: [
                    "tst_test.qml",
                ]
            }
        }
        

        file: autotest-qml/tst_tet.qml

        import QtQuick 2.9
        import QtTest 1.0
        
        TestCase {
            name: "Tests"
        
            function test_math() {
                compare(2 + 2, 4, "2 + 2 = 4")
            }
        }
        

        file: autotest-qml/main.cpp

        #include <QtQuickTest/quicktest.h>
        
        QUICK_TEST_MAIN()
        

        QtCreator build config:

        qbs.exe build -d build-project-Desktop_Qt_5_9_2_MinGW_32bits-Debug -f project.qbs --settings-dir C:\Users\xxxxx\AppData\Roaming\QtProject\qtcreator --clean-install-root --jobs 4 config:debug qbs.defaultBuildVariant:debug profile:qtc_Desktop__ea09e2b0

        qbs.exe build build -d build-project-Desktop_Qt_5_9_2_MinGW_32bits-Debug -f project.qbs --settings-dir C:\Users\xxxxx\AppData\Roaming\QtProject\qtcreator -p autotest-runner --jobs 4 config:autotest qbs.defaultBuildVariant:debug profile:qtc_Desktop__ea09e2b0


        When building, this is the following compile output:

        16:12:39: Running steps for project project...
        16:12:39: Starting: "qbs.exe" build -d build-project-Desktop_Qt_5_9_2_MinGW_32bits-Debug -f project.qbs --settings-dir C:\Users\xxxxx\AppData\Roaming\QtProject\qtcreator -p autotest-runner --jobs 4 config:autotest qbs.defaultBuildVariant:debug profile:qtc_Desktop__ea09e2b0
        Restoring build graph from disk
        Resolving project for configuration autotest
        Building for configuration autotest
        Running test ut-qml.exe
        Running test ut-cpp.exe
        build-project-Desktop_Qt_5_9_2_MinGW_32bits-Debug\autotest\install-root\ut-cpp.exe
        ********* Start testing of ut_cpp *********

        Config: Using QtTest library 5.9.2, Qt 5.9.2 (i386-little_endian-ilp32 shared (dynamic) debug build; by GCC 5.3.0)

        PASS : ut_cpp::initTestCase()

        PASS : ut_cpp::test()

        PASS : ut_cpp::cleanupTestCase()

        Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 1ms

        ********* Finished testing of ut_cpp *********

        Build done for configuration autotest.
        16:12:40: The process "qbs.exe" exited normally.
        16:12:40: Elapsed time: 00:01.


        As you can see, only the cpp unit-test is executed. How to also execute the qml one?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post