> The Unit Test Framework > User's guide > Test organization > Test case template > 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(test_case_name, formal_type_parameter_name, collection_of_types)
The macro BOOST_AUTO_TEST_CASE_TEMPLATE requires three arguments:
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 |
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"