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 ;
To add testing to a CMake-based project, simply include(CTest) and use the add_test command.
Create a Boost. cpp file for your tests, right-click on the project node in Solution Explorer and choose Add > New Item. In the Add New Item dialog, expand Installed > Visual C++ > Test. Select Boost. Test, then choose Add to add Test.
CTest is the part of CMake that handles testing your code. CTest allows for an easy way to run your newly built programs with various argument and option settings, and then check the results against expected output.
Boost unit testing framework (Boost. Test) is a part of the Boost library. It is a fully-functional and scalable framework, with wide range of assertion macros, XML output, and other features. Boost. Test itself lacks mocking functionality, but it can be combined with stand-alone mocking frameworks such as gmock.
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
and target_link_libraries
in your CMakeLists.txt
script. Then, you can add the unit test binary to the list of tests for CTest to run with enable_testing
and add_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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With