Unit Tests

We use doctest to create a benchmark for the C++ code.

The test subfolder contains all the code related to the C++ unit tests. In main.cpp implements the benchmarks runner, The unit tets are implemented in test_*.cpp. Assuming your project is names cpptools, the test folder looks like.

project
├── ...
├── test
│   ├── CMakeLists.txt
│   ├── main.cpp
│   ├── test_cpptools_config.cpp
└── ...

Build System

There is a meta target called test_cpptools (assuming your cpptools is the package name) which bundles the build process of unit tests. Assuming you cmake-build directory is called bld the following will build all examples.

$ cd bld
$ make test_cpptools

To run the actual test you can use the target cpp_tests

$ cd bld
$ make cpp_tests

Adding New Tests

To add new tests just add a new cpp file to the test folder and update the CMakeLists.txt. Assuming we named the new cpp file test_my_new_feture.cpp, the relevant part in the CMakeLists.txt shall look like this:

# all tests
set(${PROJECT_NAME}_TESTS
    test_cpptools_config.cpp
    test_my_new_feture.cpp
)

After changing the CMakeLists.txt cmake needs to be rerun to configure the build again. After that make examples will build all examples including the freshly added examples.

$ cd bld
$ cmake .
$ make examples