【发布时间】:2009-03-23 06:26:38
【问题描述】:
我正在使用 UnitTest++ 对 C++ 代码进行单元测试。
在我的测试中,有一组测试我会重复几次。我想要一个实用函数来执行这些测试。简而言之,我想接受这个:
TEST( foo ) {
Foo one;
Foo two;
// init one & two
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cycles
}
TEST( bar ) {
Foo one;
Foo two;
// init one & two
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5); in repeating cycles
}
然后使用这个:
void blah( const Foo& one, const Foo& two ) {
// lots of CHECK_CLOSE(one.bar, two.bar, 1e-5);
}
TEST( foo ) {
Foo one;
Foo two;
// init one & two
blah(one, two);
}
TEST( bar ) {
Foo one;
Foo two;
// init one & two
blah(one, two);
}
由于 UnitTest++ 的宏操作,这不起作用。解决这个问题的最佳方法是什么?
编辑:我现在无法查看的一些想法。
- 如果我使用带有
struct中的实用程序函数的夹具,我是否能够从该函数中调用 UnitTest++ 宏? - 我可以编写一个宏来执行常见的测试。我不是很喜欢这样,但至少我会干瞪眼……
【问题讨论】:
标签: c++ unit-testing