This example show how to use the Google Test framework to write unit tests for your code. See lecture notes here for more examples.
Whilst this project is part of a larger set of examples it can be copied into your own project and built using the following commands:
cmake -G Ninja -B build -S .
cmake --build build
cd build
./GTestBoilerPlate
It is also possible to use the ctest command to run the tests, this is useful if you have a large number of tests and want to run them all at once.
If building at home or wanting to try a newer version of GTest (if avaliable) you can use the vcpkg manifest mode to install the libraries needed for this project. To do this you need to add the following to the cmake command line:
mkdir build
cd build
cmake -G Ninja -DVCPKG_MANIFEST_DIR=../manifest/ ..
cmake --build .
This will read the file vcpkg.json and install the libraries needed for this project, just in this local folder. At home this can be useful as well.