Skip to content
Snippets Groups Projects
Select Git revision
  • 5d4922aa328447c93581c34a9ab841e59bf78bc4
  • master default protected
2 results

Qt-and-QML-testing-tools.md

  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.

    C++

    Google Test

    Google's c++ test framework.

    Installation

    • Ubuntu / Debian: apt install googletest libgtest-dev

    Example main.cpp

    #include <gtest/gtest.h>
    
    TEST(Test, Test1)
    {
        EXPECT_EQ(0, 0); // OK
        EXPECT_EQ(1, 0); // ERROR and continues
        ASSERT_EQ(0, 0); // OK
        ASSERT_EQ(1, 0); // ERROR and stops execution
    }
    
    int main(int argc, char *argv[])
    {
        ::testing::InitGoogleTest(&argc, argv);
        return RUN_ALL_TESTS();  // Runs Test1 and any other included test
    }

    QML

    QtQuickTest

    Installation

    • Ubuntu / Debian: apt install qml-module-qqtest libqt5quicktest5

    • Example main.cpp

    #include <QtQuickTest/quicktest.h>
    #include <QQmlEngine>
    
    class Setup : public QObject
    {
        Q_OBJECT
    
    public:
        Setup() {}
    
    public slots:
    
        void qmlEngineAvailable(QQmlEngine *engine)
        {
            // Code to be run before the tests
        }
    };
    
    QUICK_TEST_MAIN_WITH_SETUP(testqml, Setup)
    #include "main.moc"