Boost Test - catching assertions, marking them as a success?
Hi, I'm looking at using Boost Test as a means to carry out unit tests and wondered if there is a guard for assertions like there is for exception handling to say, "this test should assert()", fail if it does not. This would be really handy, especially if it was available in the Auto unit tests: BOOST_AUTO_UNIT_TEST_SHOULD_ASSERT( object_calls_assert ) { myobject foo; foo.callAssert(); } or something similar. Kevin -- | Kevin Wheatley, Cinesite (Europe) Ltd | Nobody thinks this | | Senior Technology | My employer for certain | | And Network Systems Architect | Not even myself |
"Kevin Wheatley"
Hi,
I'm looking at using Boost Test as a means to carry out unit tests and wondered if there is a guard for assertions like there is for exception handling to say, "this test should assert()", fail if it does not.
If you mean an ability to intersept assert function call() - no it can't be done reliably. If could change implementation of your function callAssert() so it throw an exception (at least in test/debug mode), then you could use BOOST_CHECK_THROW. Gennadiy.
Gennadiy Rozental wrote:
If you mean an ability to intersept assert function call() - no it can't be done reliably. If could change implementation of your function callAssert() so it throw an exception (at least in test/debug mode), then you could use BOOST_CHECK_THROW.
Gennadiy.
Gennadiy, Unfortunately, this works for my code but not for 3rd party libraries (brain dead though they may be :-) I was thinking of a THROWING_ASSERT() or somthing which would do just as you suggested for our code. I just felt it would be good to test the 3rd party in the same way as our own code. Thanks Kevin -- | Kevin Wheatley, Cinesite (Europe) Ltd | Nobody thinks this | | Senior Technology | My employer for certain | | And Network Systems Architect | Not even myself |
Kevin Wheatley wrote:
Unfortunately, this works for my code but not for 3rd party libraries (brain dead though they may be :-) I was thinking of a THROWING_ASSERT() or somthing which would do just as you suggested for our code. I just felt it would be good to test the 3rd party in the same way as our own code.
So ignoring the 3rd party code for now I've decided to implement something using BOOST_ASSERT() and BOOST_ENABLE_ASSERT_HANDLER, then having assertion_failed() throw the exception. The test code then expects the throw and the developers are happy (no errors :-) Thanks Kevin -- | Kevin Wheatley, Cinesite (Europe) Ltd | Nobody thinks this | | Senior Technology | My employer for certain | | And Network Systems Architect | Not even myself |
participants (2)
-
Gennadiy Rozental
-
Kevin Wheatley