c++ - Boost 测试库使用不同的 "parameters"运行套件两次

标签 c++ boost boost-test

我有一套可以在几种不同模式下运行的测试。除了一些全局配置或夹具配置之外,测试用例代码是相同的。

boost 测试库中是否有某种方法可以实现这一点,而不必围绕所有单独的测试用例编写包装器?

请注意,这不是命令行开关,它应该是同一执行的一部分。

最佳答案

unary function test case可能是你想要的。唯一的缺点是它似乎不支持自动注册(可能基于某种工厂功能)。

他们还有test case template并且确实具有自动注册功能,因此如果没有太多配置,则可以通过为每个配置定义类型来滥用它。

编辑:测试用例模板可以这样使用:

// Parameter is the type of parameter you need. Might be anything from simple int (in
// which case the template parameter may be a value, not reference) to complex object.
// It just has to be possible to create (static) global instances of it.

template <const Parameter &param>
struct Fixture {
    // do whatever you want, param is normal object reference here
    // it's not a member, but you can:
    const Parameter &getParameter() { return param; }
}

static Parameter p1(whatever);
static Parameter p2(something_else);
// ...

typedef boost::mpl::list<Fixture<p1>, Fixture<p2> > Fixtures;

BOOST_AUTO_TEST_CASE_TEMPLATE(test, F, Fixtures)
{
    F fixture; // Unfortunately you can't make it true fixture, so you have to have instance
    // Test what you want
}

关于c++ - Boost 测试库使用不同的 "parameters"运行套件两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6425056/

相关文章:

c++ - boost 链接器错误错误的工具集

c++ - C++ 中的轻量级反射

c++ - Boost.Test 和 fork

C++ 创建图像

c++ - QTreeWigetItem - 如何管理点击直接更改项目文本的名称

c++ - 打印unicode字符c++ linux

c++ - 从 .so 导入函数

c++ - 拥有包含用于单元测试的 MFC 项目和控制台应用程序的解决方案

c++ - BOOST.Test 中的全局固定装置如何工作?

c++ - 如何将结构模板标记为好友?