如这里所暗示的,如何使用免费的固定功能(设置和拆卸):灵活的模型?文档没有显示示例,库测试也不使用这种情况。我正在寻找测试套件的示例。
问问题
275 次
1 回答
1
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
...
注意在套件运行之前调用 setup 和最后调用 teardown 。
于 2016-08-03T19:52:06.537 回答