path: root/src/testlib
diff options
authorLeena Miettinen <>2019-10-15 16:54:30 +0200
committerLeena Miettinen <>2019-12-06 09:00:28 +0100
commit5da34ac263b6beb6666192acfdead1c028278e17 (patch)
tree4c3fb0ce4adcf48590957da31b74d26c9778f1b5 /src/testlib
parent20266820a31d5cd4afc808bc8b3e9eb6e0396358 (diff)
Doc: Update info about building tests
Task-number: QTBUG-63987 Change-Id: I4b6e8f35afc9d3ca10b393a0305bbb51bf81ec26 Reviewed-by: Christian Stenger <> Reviewed-by: Paul Wicking <>
Diffstat (limited to 'src/testlib')
2 files changed, 55 insertions, 2 deletions
diff --git a/src/testlib/doc/snippets/code/doc_src_cmakelists.txt b/src/testlib/doc/snippets/code/doc_src_cmakelists.txt
new file mode 100644
index 0000000000..96dbe1acee
--- /dev/null
+++ b/src/testlib/doc/snippets/code/doc_src_cmakelists.txt
@@ -0,0 +1,14 @@
+project(mytest LANGUAGES CXX)
+find_package(Qt5Test REQUIRED)
+add_executable(mytest tst_mytest.cpp)
+add_test(NAME mytest COMMAND mytest)
+target_link_libraries(mytest PRIVATE Qt5::Test)
diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc
index 19d871d404..688cc2f2f6 100644
--- a/src/testlib/doc/src/qttestlib-manual.qdoc
+++ b/src/testlib/doc/src/qttestlib-manual.qdoc
@@ -83,6 +83,10 @@
\li Custom types can easily be added to the test data and test output.
+ You can use a Qt Creator wizard to create a project that contains Qt tests
+ and build and run them directly from Qt Creator. For more information, see
+ \l {Running Autotests}.
\section1 Creating a Test
To create a test, subclass QObject and add one or more private slots to it. Each
@@ -133,6 +137,41 @@
\if !defined(qtforpython)
\section1 Building a Test
+ You can build an executable that contains one test class that typically
+ tests one class of production code. However, usually you would want to
+ test several classes in a project by running one command.
+ See \l {Chapter 1: Writing a Unit Test}{Writing a Unit Test} for a step by
+ step explanation.
+ \section2 Building with CMake and CTest
+ You can use \l {CMake and CTest} to create a test.
+ \l{}{CTest} enables
+ you to include or exclude tests based on a regular expression that is
+ matched against the test name. You can further apply the \c LABELS property
+ to a test and CTest can then include or exclude tests based on those labels.
+ All labeled targets will be run when \c {test} target is called on the
+ command line.
+ There are several other advantages with CMake. For example, the result of
+ a test run can be published on a web server using CDash with virtually no
+ effort.
+ CTest scales to very different unit test frameworks, and works out of the
+ box with QTest.
+ The following is an example of a CMakeLists.txt file that specifies the
+ project name and the language used (here, \e mytest and C++), the Qt
+ modules required for building the test (Qt5Test), and the files that are
+ included in the test (\e tst_mytest.cpp).
+ \quotefile code/doc_src_cmakelists.txt
+ For more information about the options you have, see \l {Build with CMake}.
+ \section2 Building with qmake
If you are using \c qmake as your build tool, just add the
following to your project file:
@@ -146,14 +185,14 @@
See the \l{Building a Testcase}{qmake manual} for
more information about \c{make check}.
+ \section2 Building with Other Tools
If you are using other build tools, make sure that you add the location
of the Qt Test header files to your include path (usually \c{include/QtTest}
under your Qt installation directory). If you are using a release build
of Qt, link your test to the \c QtTest library. For debug builds, use
- See \l {Chapter 1: Writing a Unit Test}{Writing a Unit Test} for a step by
- step explanation.
\section1 Qt Test Command Line Arguments