Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Flux Capacitor Tests
Of course the flux capacitor library has a few tests to verify its behaviour.
In the next exercise we will use command
add_executable to build a test executable for the flux capacitor library.
Because we want to run tests automatically on each build, we will use command
add_custom_target to add a custom target that runs the flux capacitors tests.
add_executable(apple-tests ...) add_custom_target(run-apple-tests ALL COMMAND apple-tests) add_custom_target(run-all-tests DEPENDS run-apple-tests run-grape-tests)
From the source files in
flux_capacitor/tests build an executable named
flux_capacitor-tests with an alias
The tests also check classes that are not part of the public interface of the flux capacitor. So, the source folder of the flux capacitor library is an include dependency for the test.
The tests are depending on
time_machine::flux_capacitor, the testing framework
catchorg::catch2 and of course
Because an executable has no dependants, all dependencies should be private.
[project]/ +--- CMakeLists.txt +--- flux_capacitor/ | +--- CMakeLists.txt | +--- include/ | | +--- flux_capacitor/ | | +--- flux_capacitor.h | +--- src/ | | +--- capacitor.cc | | +--- capacitor.h | | +--- flux_capacitor.cc | | +--- flux.cc | | +--- flux.h | +--- tests/ | +--- CMakeLists.txt | +--- capacitor.cc | +--- flux_capacitor.cc | +--- flux.cc | +--- vendor | +--- CMakeLists.txt | +--- catch2/ | +--- CMakeLists.txt | +--- ... +--- ...
Then add a custom target named
run-flux_capacitor-tests that runs the tests.