My project uses CMake as its build system, and I want it to execute my Boost.Test test cases.
How can I achieve that? In Boost.Build, I could do it as follows:
import testing ;
use-project /my_lib : ../src ;
unit-test my_test
: my_test.cpp
/my_lib
boost_unit_test_framework
;
lib boost_unit_test_framework ;
I've made some modules at https://github.com/rpavlik/cmake-modules/ including some for integrating boost test - see the readme in that repo for info on the easiest way to use them.
Then, you'd want to do the following, assuming test_DimensionedQuantities.cpp is a boost.test test driver source.
This adds just a single CTest-visible test that fails if any of the boost tests fail. If you have tests that can be specified by name to the test driver (the simplest macros fall in this category), you can do something like this:
There are a bunch more options, including configuring a header to choose the best option of a: included version of UTF, b: static link, or c: dynamic link, as well as linking against libraries, etc. Just look in the cmake file for info.
CMake itself is just a build system; CTest is a just test runner that is integrated with CMake. Neither is a unit test framework; that job can be done by Boost.Test or googletest.
To use a Boost.Test-based unit test program in a CMake project, you'd first have CMake build and link your unit test binary, using
add_executable
andtarget_link_libraries
in yourCMakeLists.txt
script. Then, you can add the unit test binary to the list of tests for CTest to run withenable_testing
andadd_test
.If you want to get really fancy, you can look through the CMake documentation for how to have CMake search through all your source files to find and build unit tests automatically, but first things first...
See the CMake test projects and/or the CTest stuff in the CMake documentation/book.