Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Boost.Test in a CMake based project?

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 ;
like image 940
forneo Avatar asked Nov 28 '10 21:11

forneo


People also ask

How do I add a test to CMake?

To add testing to a CMake-based project, simply include(CTest) and use the add_test command.

How do I run a unit test boost Visual Studio?

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.

Is CTest part of CMake?

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.

What is boost testing?

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.


1 Answers

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...

like image 142
Ben Karel Avatar answered Sep 29 '22 06:09

Ben Karel