是否有可能使用BOOST_PARAM_TEST_CASE上的boost ::测试的自动注册? [英] Is it possible to use BOOST_PARAM_TEST_CASE with automatic registration on boost::test?
问题描述
是否有可能混淆了 BOOST_AUTO_TEST_CASE
和 BOOST_AUTO_TEST_CASE_TEMPLATE
与 BOOST_PARAM_TEST_CASE <宏/ code>以任何方式?我在实现这一点的真的很乱方面甚至有兴趣。
Is it possible to mix up the BOOST_AUTO_TEST_CASE
and BOOST_AUTO_TEST_CASE_TEMPLATE
macros with the BOOST_PARAM_TEST_CASE
in any way? I'm even interested in really messy ways of making this happen.
有手工打造您的所有测试案例似乎真的乏味。但 BOOST_PARAM_TEST_CASE
机制是pretty织补有用的,但前提是你有一个测试初始化函数,这反过来又要求你必须使用手动测试用例建设进行工作。
Having to build all of your test cases by hand seems really tedious. But the BOOST_PARAM_TEST_CASE
mechanism is pretty darn useful, but only works if you have a test init function, which in turn requires you to have be using manual test case construction.
有没有关于如何自己挂接到自动化系统,让您可以提供自己的任何测试文档自动注册自己呢?
Is there any documentation on how to hook into the automated system yourself so you can provide your own tests that auto-register themselves?
我使用升压1.46现在。
I'm using boost 1.46 right now.
推荐答案
我写我自己的这种支持,因为真的似乎没有任何良好的支持。这就要求C ++ 11 decltype
功能和 ::性病:: remove_const
和 ::性病:: remove_reference
库的方法来工作。
I wrote my own support for this since there really didn't seem to be any good support. This requires the C++11 decltype
feature and the ::std::remove_const
and ::std::remove_reference
library methods to work.
宏定义的修改版本的 BOOST_FIXTURE_TEST_CASE
和 BOOST_AUTO_TEST_CASE
宏。
The macro definitions are a modified versions of the BOOST_FIXTURE_TEST_CASE
and BOOST_AUTO_TEST_CASE
macros.
您使用此通过这样的声明功能:
You use this by declaring your function thus:
BOOST_AUTO_PARAM_TEST_CASE(name, begin, end)
{
BOOST_CHECK_LT(param, 5); // The function will have an argument named 'param'.
}
下面是定义 BOOST_AUTO_PARAM_TEST_CASE
微距头:
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/parameterized_test.hpp>
#include <type_traits>
#define BOOST_FIXTURE_PARAM_TEST_CASE( test_name, F, mbegin, mend ) \
struct test_name : public F { \
typedef ::std::remove_const< ::std::remove_reference< decltype(*(mbegin)) >::type>::type param_t; \
void test_method(const param_t &); \
}; \
\
void BOOST_AUTO_TC_INVOKER( test_name )(const test_name::param_t ¶m) \
{ \
test_name t; \
t.test_method(param); \
} \
\
BOOST_AUTO_TU_REGISTRAR( test_name )( \
boost::unit_test::make_test_case( \
&BOOST_AUTO_TC_INVOKER( test_name ), #test_name, \
(mbegin), (mend))); \
\
void test_name::test_method(const param_t ¶m) \
// *******
#define BOOST_AUTO_PARAM_TEST_CASE( test_name, mbegin, mend ) \
BOOST_FIXTURE_PARAM_TEST_CASE( test_name, \
BOOST_AUTO_TEST_CASE_FIXTURE, \
mbegin, mend)
这篇关于是否有可能使用BOOST_PARAM_TEST_CASE上的boost ::测试的自动注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!