![]() |
Home | Libraries | People | FAQ | More |
If you are just want to write quick simple test in environment where you never used Boost.Test before - yes, use included components. But if you plan to use Boost.Test on permanent basis, small investment of time needed to build (if not build yet), install and change you makefiles/project settings will soon return to you in a form of shorter compilation time. Why do you need to make your compiler do the same work over and over again?
It's really easy to switch to automatic registration. And you don't need to worry about forgotten test cases.
In some cases you are reusing the same template based code from within one
test case (actually we recommend better solution in such case - see below).
Now if an error gets reported by the test tool within that reused code you
may have difficulty locating were exactly error occurred. To address this
issue you could either a add BOOST_TEST_MESSAGE
statements in
templated code that log current type id of template parameters or you can
use special hook located in unit_test_result.hpp
called
first_failed_assertion()
.
If you set a breakpoint right on the line where this function is defined
you will be able to unroll the stack and see where error actually occurred.
If you writing unit test for generic reusable component you may have a need to test it against set of different template parameter types . Most probably you will end up with a code like this:
template<typename TestType> void specific_type_test( TestType* = 0 ) { MyComponent<TestType> c; // ... here we perform actual testing } void my_component_test() { specific_type_test( (int*)0 ); specific_type_test( (float*)0 ); specific_type_test( (UDT*)0 ); // ... }
This is namely the situation where you would use test case template facility. It not only simplifies this kind of unit testing by automating some of the work, in addition every argument type gets tested separately under unit test monitor. As a result if one of types produce exception or non-fatal error you may still continue and get results from testing with other types.