Skip to content

dstrebkov/cpp-unit-testing-frameworks-demo

Repository files navigation

cpp-unit-testing-frameworks-demo

cpp-cmake-project-template language repo size

Sample CMake-based C++ application that demonstrates setup and basic usage of several Unit Testing Frameworks for C++.

CMake ≥ 3.14.0 is required.

Contents

All unit testing frameworks except Criterion are obtained as sources from GitHub using CMake's functions FetchContent_Declare() and FetchContent_MakeAvailable().

Criterion

Criterion framework is added to the project as Linux release binaries taken from GitHub via FetchContent_Declare() and FetchContent_Populate() since that framework has migrated from CMake to Meson build system since v2.4.0 on February, 2022. Criterion binaries are available for Linux platform only - in case of other platform (i.e. Windows) corresponding library factorial_criterion would not be built.

Boost.Test

Support of the library that uses Boost.Test (factorial_boost) is currently under conditional compilation and is disabled by default. Check instructions below on how it could be enabled, but that would require time consuming fetching of Boost sources and its building.

Instructions

Start by doing:

mkdir cmake-build
cd cmake-build/

Next, if not using Boost.Test-based demo library, execute:

cmake ..
make

Otherwise, execute:

cmake -DBUILD_FACTORIAL_BOOST_TEST_LIB=ON ..
make

Run app_factorial application:

cd app_factorial/
./app_factorial

Run unit tests (called from cmake-build folder):

cd ..
ctest

Project structure

Placeholder XXX on depicted structure below stands for the name of the used unit testing framework.

.
│
├── app_factorial/             # Facorial application binary
│   ├── include                # Application includes (empty)
│   ├── src                    # Application sources
│   │   └── main.cpp           # Main entry of the sample factorial application
│   ├── test/                  # Application test folder (empty)
│   └── CMakeLists.txt         # Compile script for application
│
├── factorial_XXX              # XXX-based static library
│   ├── include                # XXX-based library includes
│   │   └── factorial.h        # XXX-based library header
│   ├── src                    # XXX-based library sources
│   │   └── factorial.cpp      # XXX-based library source
│   ├── test/                  # XXX-based library tests
│   │   ├── factorial_test.cpp # Tests for XXX-based library
│   │   └── CMakeLists.txt     # Compile script for tests of XXX-based library
│   └── CMakeLists.txt         # XXX-based library compile script
│
├── .....
│
└── CMakeLists.txt             # Main compile script

Useful Links

Releases

No releases published

Packages

No packages published