Boost logo

Boost Users :

Subject: [Boost-users] [test] boost::test equivalent of CppUnit's "protectors" ?
From: Tim Day (timday_at_[hidden])
Date: 2009-04-30 08:58:36


I've used both CppUnit and boost::test for C++ unittesting. Generally I
prefer boost::test, mainly because the auto-test macros minimise the
effort to setup tests. But there's one thing I really miss from CppUnit:
the ability to register your own custom "protectors", instances of which
automatically wrap all the run tests. (Technically, you install a test
"listener", and that can wrap each test run in a protector scope.
Multiple listeners and nested protectors are possible).

I've found these invaluable in the past for monitoring unittests for
unexpected side effects (e.g checking code hasn't changed the
floating-point unit state flags, or messed with other global state). I
can't see any equivalent in the boost::test documentation, although
BOOST_FIXTURE_TEST_CASE maybe comes closest. (However, whereas a
CppUnit protector can return a bool to indicate pass/fail, it's less
clear to me how a fixture destructor should indicate failure).

Any suggestions for how to best achieve the same thing as CppUnit's
protectors in boost::test (and without updating the body of each test) ?

Thanks for any advice
Tim


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net