Minimal
//
// Notes:
// -----
// o no main() required. It's provided by framework.
// o Executables can be invoked with -help
//
// BOOST_TEST_MODULE defines the name of the program (will be used in messages)
// BOOST_TEST_MODULE must be defined before include boost/test/included/unit_test.hpp
#define BOOST_TEST_MODULE MinimalTest
#include <boost/test/included/unit_test.hpp>
int sum(int a, int b) {
return a+b;
}
int diff(int a, int b) {
return a*b;
}
// Declare a test case (with the macro BOOST_AUTO_TEST_CASE):
BOOST_AUTO_TEST_CASE(test_one)
{
BOOST_CHECK(sum (20, 22) == 42);
BOOST_CHECK(diff(10, 15) == 5);
}
// Declare another test
BOOST_AUTO_TEST_CASE(test_two)
{
BOOST_CHECK(true);
}
BOOST_FIXTURE_TEST_SUITE
#include <iostream>
#define BOOST_TEST_MODULE TestName
#include <boost/test/included/unit_test.hpp>
struct MyFixture {
MyFixture () {
std::cout << "MyFixture c'tor" << std::endl;
}
~MyFixture () {
std::cout << "MyFixture d'tor" << std::endl;
}
};
//
// The fixtures initiates and destructs
// the definable MyFixture for every test
// case below (BOOST_AUTO_TEST_CASE)
//
BOOST_FIXTURE_TEST_SUITE(foo_bar, MyFixture)
BOOST_AUTO_TEST_CASE(test_one){
BOOST_CHECK(true);
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_CASE(test_two){
BOOST_CHECK(true);
BOOST_CHECK(true);
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()