4

I always used automatic registration with Boost Test. Now I wonder, what manual registration is for ? Are there cases that automatic registration cannot handle ?

Additional remark, this time I will use turtle for mocks as well.

Edit: Seems that my question is not clear, more precisely:

  1. When should I use manual registration instead of automatic registration ?
  2. Why would I do so ? What are real life situations for which automatic registration is not enough ?
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
Thelvyn
  • 264
  • 3
  • 8

4 Answers4

1

According to the documentation

To alleviate this issue the UTF presents facilities for automated (in place) test case creation and registration in the test tree. These facilities sacrifice some generality and work for selected test function signatures only.

However, I have never come across a situation where automatic test registration failed. E.g. you can test functions (with BOOST_AUTO_TEST_CASE), function templates (with BOOST_AUTO_TEST_CASE_TEMPLATE) and member functions of a Fixture class (with BOOST_FIXTURE_TEST_CASE).

TemplateRex
  • 69,038
  • 19
  • 164
  • 304
1

When you want fine grained control over what is tested and in what order. For exampe based on command line arguments.

Gennadiy Rozental
  • 1,905
  • 2
  • 13
  • 17
1

In my case, because of how I wanted the testing done, manual registration was easier.

This is because I had a small number of tests that were applied to a large number of classes each implementing the same interface. These were file format handlers that supported many different file formats, and I wanted to perform the same set of tests on each (e.g. open a file in each format and try to read some data.)

Originally I was using automatic registration, and I had to duplicate the test cases for each supported file format. I actually did this with an #include and some precompiler tricks, but nevertheless it was difficult to maintain.

Instead I have now switched to manual registration, as this allows me to create one set of tests, and have those tests added to the tree dozens of times, with each copy running against a different class (to test each file format.) The code is a lot cleaner and most of the #ifdef lines have now gone which is nice.

The answer to your question is similar to whether you would solve a C++ coding problem with metaprogramming or not. C++ metaprogramming can be a bit like automatic copy-and-paste so you can type less code, writing a more generic algorithm and having the compiler do the work instead. Manual registration with Boost.Test is similar, letting you specify your list of tests with an algorithm (code) instead of listing each one separately.

Of course if most of your tests are unique, and you're not running the same test repeatedly with different parameters, then you probably won't see any benefit from switching to manual registration.

Malvineous
  • 25,144
  • 16
  • 116
  • 151
0

http://www.boost.org/doc/libs/1_50_0/libs/test/doc/html/utf/user-guide/test-organization/manual-nullary-test-case.html

You can use class member-functions with boost::bind, you can bind args to functions etc

If you use only free function based test cases advance to the automatic registration facility It's really easy to switch to automatic registration. And you don't need to worry about forgotten test case anymore

http://www.boost.org/doc/libs/1_50_0/libs/test/doc/html/utf/usage-recommendations/generic.html

ForEveR
  • 55,233
  • 2
  • 119
  • 133