diff --git a/Qt-and-QML-testing-tools.md b/Qt-and-QML-testing-tools.md new file mode 100644 index 0000000000000000000000000000000000000000..e72575e50359752f3151709a578ab7399afd4968 --- /dev/null +++ b/Qt-and-QML-testing-tools.md @@ -0,0 +1,58 @@ +# 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" +``` \ No newline at end of file