boost test with assert()
Hello, I use this test class: class SimulationIdTest { public: static void TestDestructorAfterAddRemoveSimulation(); static void TestDestructorAfterAddRemoveContractSimulation(); static void AddTests(boost::unit_test::test_suite* suite); }; TestDestructorxxx() are written so that the code inside, indirectly, throws an assert(false) (not my code) I would like to test that indeed, it does throw the assert(false). void SimulationIdTest::AddTests(boost::unit_test::test_suite* suite) { suite->add(BOOST_TEST_CASE(TestDestructorAfterAddRemoveSimulation), 1); } I tried the above by saying there would be 1 failure, however the test suite stops on that failure ( the assert(false) ), even the second argument of suite->add is 1. Is there a solution to this case? Regards,
Hicham Mouline wrote:
Hello,
I use this test class:
What is your environment?
class SimulationIdTest { public: static void TestDestructorAfterAddRemoveSimulation();
static void TestDestructorAfterAddRemoveContractSimulation();
static void AddTests(boost::unit_test::test_suite* suite); };
TestDestructorxxx() are written so that the code inside, indirectly, throws an assert(false) (not my code)
Catching an assert is tricky business, rarely successful.
I would like to test that indeed, it does throw the assert(false).
void SimulationIdTest::AddTests(boost::unit_test::test_suite* suite) { suite->add(BOOST_TEST_CASE(TestDestructorAfterAddRemoveSimulation), 1); }
I tried the above by saying there would be 1 failure, however the test suite stops on that failure ( the assert(false) ), even the second argument of suite->add is 1.
Assert is fatal error. Even if I am able to catch it I'll stop test execution immediately after. Gennadiy.
participants (2)
-
Gennadiy Rozental
-
Hicham Mouline