使用免费功能的 Boost 单元测试框架装置
Boost Unit test framework fixtures using free functions
如何使用此处提示的固定装置(设置和拆卸)的免费功能:flexible models?文档没有显示示例,库测试也没有使用这种情况。我正在寻找测试套件的示例。
FWIW,这对我有用:
#define BOOST_TEST_MODULE foo
#include <boost/test/included/unit_test.hpp>
namespace utf = boost::unit_test;
void setup () { BOOST_TEST_MESSAGE("set up fun"); }
void teardown () { BOOST_TEST_MESSAGE("tear down fun"); }
BOOST_AUTO_TEST_SUITE(bar, *utf::fixture (&setup, &teardown))
BOOST_AUTO_TEST_CASE(test1) {
BOOST_TEST_MESSAGE("running test1");
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(test2) {
BOOST_TEST_MESSAGE("running test2");
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE_END()
运行:
$ clang++ -I/usr/local/include test.cpp && ./a.out --log_level=all
Running 2 test cases...
Entering test module "foo"
test.cpp:9: Entering test suite "bar"
set up fun
test.cpp:11: Entering test case "test1"
running test1
test.cpp:13: info: check true has passed
test.cpp:11: Leaving test case "test1"; testing time: 56us
test.cpp:16: Entering test case "test2"
running test2
test.cpp:18: info: check true has passed
test.cpp:16: Leaving test case "test2"; testing time: 36us
tear down fun
test.cpp:9: Leaving test suite "bar"; testing time: 148us
Leaving test module "foo"; testing time: 244us
...
请注意在套件 运行 之前调用设置,在最后调用拆解。
如何使用此处提示的固定装置(设置和拆卸)的免费功能:flexible models?文档没有显示示例,库测试也没有使用这种情况。我正在寻找测试套件的示例。
FWIW,这对我有用:
#define BOOST_TEST_MODULE foo
#include <boost/test/included/unit_test.hpp>
namespace utf = boost::unit_test;
void setup () { BOOST_TEST_MESSAGE("set up fun"); }
void teardown () { BOOST_TEST_MESSAGE("tear down fun"); }
BOOST_AUTO_TEST_SUITE(bar, *utf::fixture (&setup, &teardown))
BOOST_AUTO_TEST_CASE(test1) {
BOOST_TEST_MESSAGE("running test1");
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(test2) {
BOOST_TEST_MESSAGE("running test2");
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE_END()
运行:
$ clang++ -I/usr/local/include test.cpp && ./a.out --log_level=all
Running 2 test cases...
Entering test module "foo"
test.cpp:9: Entering test suite "bar"
set up fun
test.cpp:11: Entering test case "test1"
running test1
test.cpp:13: info: check true has passed
test.cpp:11: Leaving test case "test1"; testing time: 56us
test.cpp:16: Entering test case "test2"
running test2
test.cpp:18: info: check true has passed
test.cpp:16: Leaving test case "test2"; testing time: 36us
tear down fun
test.cpp:9: Leaving test suite "bar"; testing time: 148us
Leaving test module "foo"; testing time: 244us
...
请注意在套件 运行 之前调用设置,在最后调用拆解。