Files
qt-creator/tests/unit
hjk 0415bea736 Tests: gtest unittest: improve compilability
... with recent (namespaced) Qt dev.

[...]tests/unit/unittest/3rdparty/googletest/googletest/include/gtest/gtest-matchers.h:184:14: error: invalid conversion from 'const char*' to 'ushort' {aka 'short unsigned int'} [-fpermissive]
In file included from /data/dev/qt-6-ns/qtbase/include/QtCore/qstring.h:1,
                 from /data/dev/qt-6-ns/qtbase/include/QtCore/QString:1,
                 from /data/dev/creator-out/src/libs/utils/smallstringview.h:9,
                 from /data/dev/creator-out/src/libs/utils/smallstringliteral.h:8,
                 from /data/dev/creator-out/src/libs/utils/smallstring.h:8,
                 from /data/dev/creator-out/src/libs/utils/smallstringvector.h:8,
                 from /data/dev/creator-out/src/libs/utils/smallstringio.h:6,
                 from /data/dev/creator-out/tests/unit/unittest/gtest-creator-printing.h:7,
                 from /data/dev/creator-out/tests/unit/unittest/googletest.h:17,
                 from /data/dev/creator-out/tests/unit/unittest/externaldependenciesmock.h:6,
                 from /data/dev/creator-out/tests/unit/unittest/modulescanner-test.cpp:4:
a/dev/qt-6-ns/qtbase/src/corelib/text/qstring.h:1006:61: note:   initializing argument 2 of 'bool Ns::operator==(const Ns::QString&, Ns::QChar)'
[104/1218] Building CXX object src/plugins/coreplugin/CMakeFiles/Core.dir/locator/executefilter.cpp.o^C

Change-Id: Id8d4533b9e53d7aa81edc64a99df31dd1d6ac5bf
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2023-06-13 08:41:23 +00:00
..

Contribution Guideline

This document summarizes;

  • Best practices for writing tests
  • How to add a new test
  • How to build only specific test

All tests here depend on the GoogleTest framework.

Best Practices

We're following those patterns/approaches;

  • The Arrange, Act, and Assert (AAA) Pattern
  • Given When Then (GWT) Pattern

Adding a New Unit Test

  • Please add your tests under unit/unittest. No subfolders are needed.

  • Name your class as foo-test.cpp

  • Always include googletest.h header. Without that you may get the printer function can be broken because the are not anymore ODR (because of weak linking to printers for example). It is also necessary for nice printers, also adds Qt known matchers.

Building Tests

Note: When you're building the application from the terminal, you can set environment variables instead of settings CMake flags. The corresponding environment variable name is same with CMake variable name but with a 'QTC_' prefix. CMake Variable: WITH_TESTS Environment Variable: QTC_WITH_TESTS

You have to enable tests with the following CMake variable otherwise the default configuration skips them.

WITH_TESTS=ON

Building Specific Tests

After enabling tests you can use test-specific CMake flags to customize which tests should be built instead of building all of them at once. Please check the relevant CMake file to see which variable is required to enable that specific test.

BUILD_TESTS_BY_DEFAULT=OFF
BUILD_TEST_UNITTEST=ON
BUILD_TEST_TST_QML_TESTCORE=ON