This recipe and the next one are devoted to auto-testing using the Boost.Test
library, which is used by many Boost libraries. Let's get hands-on with it and write some tests for our own class:
#include <stdexcept> struct foo { int val_; operator int() const; bool is_not_null() const; void throws() const; // throws(std::logic_error) };
Basic knowledge of C++ is required for this recipe. To compile code of this recipe, define BOOST_TEST_DYN_LINK
macro and link against the boost_unit_test_framework
and boost_system
libraries.
To be honest, there is more than one test library in Boost. We'll take a look at the most functional one.
- To use it, we need to define the macro and include the following header:
#define BOOST_TEST_MODULE test_module_name #include <boost/test/unit_test.hpp>
- Each set of tests must be written in the test case:
BOOST_AUTO_TEST_CASE(test_no_1) {
- Checking some function for the
true
result must be...