Boost logo

Boost Users :

Subject: Re: [Boost-users] [test] manual test suite initialization: linking?problems
From: Gennadiy Rozental (rogeeff_at_[hidden])
Date: 2009-07-19 03:52:35


Matthias Vallentin <vallentin <at> icsi.berkeley.edu> writes:

> That's neat. How can I specify the hierarchy of different suites?

You should be able to build whatever hierarchy you want.
 
> I assume I cannot switch between automatic and manual registration
> within one compilation unit. How could I achieve such a structure then?

You can in a sense. Automatic test units registered first though, thus you can't
recreate them, but should be able to access appropriate test unit.

Also automated test suites are "restartable" in C++ namespace sense.
 
> Here is the example again. First, the master test suite (test1.cc):
>
> #define BOOST_TEST_DYN_LINK
> #include <boost/test/unit_test.hpp>
>
> void test()
> {
> BOOST_CHECK_EQUAL(true, false);
> BOOST_REQUIRE_EQUAL(1, 1);
> }
>
> bool init_unit_test()
> {
> boost::unit_test::test_suite* ts = BOOST_TEST_SUITE("test suite");
> ts->add(BOOST_TEST_CASE(&test));
>
> boost::unit_test::framework::master_test_suite().add(ts);
>
> return true;
> }

This is not master test suite. Master test suite is managed by the framework. It
always exists. you create test units under it.
 
> Then, I would like to add child suite automatically (test2.cc):

You can't add automatically registered test suite to the manual one for the
reasons explained above.
 
> #define BOOST_TEST_MODULE foo test suite
> #include <boost/test/unit_test.hpp>
>
> BOOST_AUTO_TEST_SUITE(foo_suite)
>
> BOOST_AUTO_TEST_CASE(foo)
> {
> BOOST_REQUIRE_EQUAL(42, 43);
> }
>
> BOOST_AUTO_TEST_SUITE_END()
>

[...]

> Running 2 test cases...
> test2.cc:8: fatal error in "foo": critical check 42 == 43 failed [42 != 43]
> test1.cc:6: error in "test": check true == false failed [true != false]
>
> *** 2 failures detected in test suite "Master Test Suite"
>
> This looks to me that test foo is part of the Master Test Suite, or am I
> mistaken?

No. It's part of the foo_suite test suite. Use --log_level=suite to see all the
test unit enter/leave messages.

Gennadiy


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