Skip to content

Commit

Permalink
Doc: Update info about building tests
Browse files Browse the repository at this point in the history
Task-number: QTBUG-63987
Change-Id: I4b6e8f35afc9d3ca10b393a0305bbb51bf81ec26
Reviewed-by: Christian Stenger <[email protected]>
Reviewed-by: Paul Wicking <[email protected]>
  • Loading branch information
leena-miettinen committed Dec 6, 2019
1 parent 2026682 commit 5da34ac
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/testlib/doc/snippets/code/doc_src_cmakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
project(mytest LANGUAGES CXX)

find_package(Qt5Test REQUIRED)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOMOC ON)

enable_testing(true)

add_executable(mytest tst_mytest.cpp)
add_test(NAME mytest COMMAND mytest)

target_link_libraries(mytest PRIVATE Qt5::Test)
43 changes: 41 additions & 2 deletions src/testlib/doc/src/qttestlib-manual.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
\li Custom types can easily be added to the test data and test output.
\endtable

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
Expand Down Expand Up @@ -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{https://cmake.org/cmake/help/latest/manual/ctest.1.html}{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:

Expand All @@ -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
\c{QtTest_debug}.

See \l {Chapter 1: Writing a Unit Test}{Writing a Unit Test} for a step by
step explanation.
\endif

\section1 Qt Test Command Line Arguments
Expand Down

0 comments on commit 5da34ac

Please sign in to comment.