This tutorial is an introduction to C++ unit testing with Qt Test. A working example is discussed and analysed in detail. Full qmake project and C++ source code are provided.
C++ unit testing with Qt Test
Qt Test is a framework for C++ unit testing. It is part of Qt, which means it includes features to test Qt GUIs and other Qt elements like signals, but it can also be used to test plain (no Qt) C++ code.
In this tutorial I am going to explain how to use Qt Test for testing a C++ class. That will involve creating a project, defining the unit test and using the different macros available to test code.
This is the first post of a series dedicated to Qt Test. The posts of this series are:
- C++ unit testing with Qt Test – part 1 – introduction
- C++ unit testing with Qt Test – part 2 – advanced testing
- GUI unit testing with Qt Test – part 1 – introduction
- GUI unit testing with Qt Test – part 2 – advanced testing
Setting up the project
The idea behind Qt Test is that each test case needs to be an independent executable and needs its own project.
The quickest way to create a project is using the “Auto Test Project” template, which is listed in the “Other Project” group of the “New Project” dialog.
The wizard will guide you through the setup of the project. In particular the Details section will let you specify several