c++ - 促进。如何在另一个测试单元中运行一个测试单元?
问题描述
我需要在当前单元的开头运行一个测试单元。我试过 BOOST_TEST_INVOKE_IF_N_ARGS 没有结果。
解决方案
您可以管理测试依赖项:
装饰器
depends_on
将装饰的测试用例(称为 TB)与另一个由名称指定的测试用例(称为 TA)相关联。这会以两种方式影响测试树的处理。首先,测试用例 TA 被命令在 TB 之前运行,不管它们被声明或添加到测试树的顺序如何。其次,如果 TA 被禁用或跳过,或者被执行并标记为失败,则跳过 TB 的执行。
#define BOOST_TEST_MODULE decorator_07
#include <boost/test/included/unit_test.hpp>
namespace utf = boost::unit_test;
// test1 and test2 defined at the bottom
BOOST_AUTO_TEST_CASE(test3, * utf::depends_on("s1/test1"))
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_CASE(test4, * utf::depends_on("test3"))
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_CASE(test5, * utf::depends_on("s1/test2"))
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_SUITE(s1)
BOOST_AUTO_TEST_CASE(test1)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_CASE(test2, * utf::disabled())
{
BOOST_TEST(false);
}
BOOST_AUTO_TEST_SUITE_END()
印刷
> decorator_07 --report_level=detailed
Running 4 test cases...
test.cpp(10): error: in "test3": check false has failed
Test module "decorator_07" has failed with:
1 test case out of 4 passed
1 test case out of 4 failed
2 test cases out of 4 skipped
1 assertion out of 2 passed
1 assertion out of 2 failed
Test case "test3" has failed with:
1 assertion out of 1 failed
Test case "test4" was skipped
Test case "test5" was skipped
Test suite "s1" has passed with:
1 test case out of 1 passed
1 assertion out of 1 passed
Test case "s1/test1" has passed with:
1 assertion out of 1 passed
推荐阅读
- php - SQLite3 LIMIT for UPDATE 和 DELETE 在 Windows 中的 PHP 上?
- react-native - TypeError:未定义不是对象(评估'Object.keys(params)')
- c++ - 在 C++ 中迭代枚举类的常用方法是什么?
- sql - 将 SQL 查询从 with 子句转移到没有 with 子句
- grails - grails如何检查双负零
- node.js - 是否有一个选项可以向我显示特定 npm 包的哪些语义版本将解析为?
- javascript - 为什么我的 React 组件将我的 JSX 渲染为文本而不是 HTML?
- javascript - ++Argument 在调用递归函数时返回的结果与参数 + 1 不同
- python - 数据帧 UDF 以获得更快的性能?
- python - 如何根据序列中的下一个值删除行?(熊猫)