如何执行boost.test库中指定的测试套件
我正在使用 Boost.Test 库在 C++ 中实现单元测试用例。假设我有两个套件,例如
BOOST_AUTO_TEST_SUITE(TestA)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
BOOST_CHECK_EQUAL(2+2, 4);
}
BOOST_AUTO_TEST_CASE(WrongAddition)
{
BOOST_CHECK_EQUAL(2 + 2, 5);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(TestB)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
bool ret = true;
BOOST_CHECK_EQUAL(ret, true);
}
BOOST_AUTO_TEST_CASE(WrongAddition)
{
BOOST_CHECK_EQUAL(2 + 2, 5);
}
BOOST_AUTO_TEST_SUITE_END()
我只想运行套件“TestB”,我该如何执行它。 我真的很感谢您的时间和帮助。抱歉,如果此问题已在其他地方发布或记录。
I am using Boost.Test library for implementing unit test cases in C++. Suppose I have two suites such as
BOOST_AUTO_TEST_SUITE(TestA)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
BOOST_CHECK_EQUAL(2+2, 4);
}
BOOST_AUTO_TEST_CASE(WrongAddition)
{
BOOST_CHECK_EQUAL(2 + 2, 5);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(TestB)
BOOST_AUTO_TEST_CASE(CorrectAddition)
{
bool ret = true;
BOOST_CHECK_EQUAL(ret, true);
}
BOOST_AUTO_TEST_CASE(WrongAddition)
{
BOOST_CHECK_EQUAL(2 + 2, 5);
}
BOOST_AUTO_TEST_SUITE_END()
and I would like to run only say suite 'TestB', how shall I execute it.
I really thank for your time and help. Sorry if this question is been posted or documented else where.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
符合此 文档,OP应使用以下参数调用单元测试可执行文件
,以仅运行测试套件
TestB
的单元测试。如果要运行所有测试套件的单元测试
CorrectAddition
,则参数为Wildcard,Boost.Test的能力相当强大,因此该参数也可以写为
Conform to this documentation, the OP should call the unit test executable with the following parameter
to run only the unit tests of test suite
TestB
.If the unit test
CorrectAddition
of all test suites shall be run, then the parameter isWildcard ability of Boost.Test is quite powerful, hence the parameter could also be written as
假设您正在使用库提供的主入口点、命令行解析等,并且还没有推出自己的,您可以在运行时通过命令行开关按名称或模式选择特定的测试套件和测试用例。
请参阅 文档中的此页面就是一个很好的示例。
Assuming you are using the library-supplied main entry point, command-line parsing, etc., and haven't rolled your own, you can select specific test suites and test cases by name or pattern via a command-line switch at run time.
See this page in the documentation for a good example.