Home > The Unit Test Framework > User's guide > Test organization > Test case template > Automated registration
PrevNext

Test case template with automated registration

To create a test case template registered in place of implementation, employ the macro BOOST_AUTO_TEST_CASE_TEMPLATE. This facility is also called auto test case template.
要創建在實現時即註冊的測試用例模板,使用宏 BOOST_AUTO_TEST_CASE_TEMPLATE。 這個工具也被稱為自動測試用例模板

BOOST_AUTO_TEST_CASE_TEMPLATE(test_case_name, formal_type_parameter_name, collection_of_types)

The macro BOOST_AUTO_TEST_CASE_TEMPLATE requires three arguments:
BOOST_AUTO_TEST_CASE_TEMPLATE 宏需要三個參數:

The test case template name
測試用例模板名稱

unique test cases template identifier
唯一的測試用例模板標識符

The name of a formal template parameter
模板參數的形式名稱

name of the type the test case template is instantiated with
用於實例化測試用例模板的類型名稱

The collection of types to instantiate test case template with
用於實例化測試用例模板的類型集合

arbitrary MPL sequence
任意的 MPL 序列

Example 14. Test case template with automated registration

#define BOOST_TEST_MODULE example
#include <boost/test/included/unit_test.hpp>
#include <boost/test/test_case_template.hpp>
#include <boost/mpl/list.hpp>

//____________________________________________________________________________//

typedef boost::mpl::list<int,long,unsigned char> test_types;

BOOST_AUTO_TEST_CASE_TEMPLATE( my_test, T, test_types )
{
    BOOST_CHECK_EQUAL( sizeof(T), (unsigned)4 )
}

//____________________________________________________________________________//
Source code | Show output
> example
Running 3 test cases...
test.cpp(12): error in "my_test<unsigned char>": check sizeof(T) == 4 failed [1 != 4]

*** 1 failure detected in test suite "example"


PrevUpHomeNext