Qt-and-QML-testing-tools.md (954B)
1 # C++ 2 3 ## Google Test 4 Google's c++ test framework. 5 6 ### Installation 7 - Ubuntu / Debian: 8 `apt install googletest libgtest-dev` 9 10 ## Example main.cpp 11 ``` 12 #include <gtest/gtest.h> 13 14 TEST(Test, Test1) 15 { 16 EXPECT_EQ(0, 0); // OK 17 EXPECT_EQ(1, 0); // ERROR and continues 18 ASSERT_EQ(0, 0); // OK 19 ASSERT_EQ(1, 0); // ERROR and stops execution 20 } 21 22 int main(int argc, char *argv[]) 23 { 24 ::testing::InitGoogleTest(&argc, argv); 25 return RUN_ALL_TESTS(); // Runs Test1 and any other included test 26 } 27 ``` 28 29 # QML 30 31 ## QtQuickTest 32 33 ### Installation 34 - Ubuntu / Debian: `apt install qml-module-qqtest libqt5quicktest5` 35 36 - Example main.cpp 37 ``` 38 #include <QtQuickTest/quicktest.h> 39 #include <QQmlEngine> 40 41 class Setup : public QObject 42 { 43 Q_OBJECT 44 45 public: 46 Setup() {} 47 48 public slots: 49 50 void qmlEngineAvailable(QQmlEngine *engine) 51 { 52 // Code to be run before the tests 53 } 54 }; 55 56 QUICK_TEST_MAIN_WITH_SETUP(testqml, Setup) 57 #include "main.moc" 58 ```