

Therefore I would like to show how easy it can be to integrate unit testing in a CMake-based project and a continuous integration (CI) server.
Cmake add test example update#
Update the TestExecutable.In my – admittedly limited – perception unit testing in C++ projects does not seem as widespread as in Java or the dynamic languages like Ruby or Python.Reference both MathLibrary and TESTFW (internal name for the test framework target) from TestExecutable: Reference MathLibrary from the main executable.Move the Sum.cpp and Sum.h files from the main executable to MathLibrary by either editing CMakeLists.txt directly, or using the File->Add Existing command in Solution Explorer: Then add a new library called MathLibrary.Add a new executable called TestExecutable:.Right-click on the project node in Solution Explorer (with CMake icon) and select Add->New Item:.When a newer version of the test framework is released, VisualGDB will update the toolchain file, without changing the CMakeLists.txt file: Instead, it will call the find_test_framework() function defined in the toolchain file, that will create the library. Note that main CMakeLists.txt file will not explicitly declare the framework t target. VisualGDB will automatically import the framework into the project as a separate target.Open VisualGDB Project Properties and reference the GoogleTest framework via the Unit Tests page:
Cmake add test example how to#

Once it is created, add a new source file to the main executable: Starting from VisualGDB 5.5R3, unit tests are supported for both cross-compiled projects and projects built directly on the target (including projects accessed directly via SSH):

Cmake add test example install#
We will start with creating a basic Raspberry Pi executable built with a cross-toolchain, and will then show how to move testable logic out of it into a static library, and how to add another target that will contain unit tests for that library.īefore you begin, install VisualGDB 5.5R3 or later. Targets (libraries and executables) are defined using concise CMake statements without duplicating any project-level settings.Common settings, such as toolchain, deployment or debug settings, are defined on the project level.This greatly simplifies the project structure: Unlike the Make-based, or MSBuild-based projects that are limited to one target per project, Advanced CMake projects can contain multiple targets (i.e. This tutorial shows how to add unit test targets to Advanced CMake projects.
