[Test] Global Fixtures

I am trying to use global fixtures in my tests but I may be misinterpreting the documentations. The following toy example doesn't work : #include <boost/test/unit_test.hpp> struct TruthFixture { int x = 3; int f (int a) { return a + 3; } }; BOOST_GLOBAL_FIXTURE( TruthFixture ) BOOST_AUTO_TEST_CASE(test_variable) { printf("x = %d\n", x); } BOOST_AUTO_TEST_CASE(test_function) { printf("f(2) = %d\n", f(2)); } the error message I get is the following: test/test.cpp:14:22: error: use of undeclared identifier 'x'; did you mean 'TruthFixture::x'? printf("x = %d\n", x); ^ TruthFixture::x test/test.cpp:4:7: note: 'TruthFixture::x' declared here int x = 3; ^ test/test.cpp:14:22: error: invalid use of non-static data member 'x' printf("x = %d\n", x); ^ test/test.cpp:18:25: error: use of undeclared identifier 'f'; did you mean 'TruthFixture::f'? printf("f(2) = %d\n", f(2)); ^ TruthFixture::f test/test.cpp:6:7: note: 'TruthFixture::f' declared here int f (int a) { ^ test/test.cpp:18:25: error: call to non-static member function without an object argument printf("f(2) = %d\n", f(2)); ^ 4 errors generated. clearly the BOOST_GLOBAL_FIXTURE declaration is not doing anything. But if I drop the global fixture declaration and revert to the per function declaration, it works: #include <boost/test/unit_test.hpp> struct TruthFixture { int x = 3; int f (int a) { return a + 3; } }; BOOST_FIXTURE_TEST_CASE(test_variable, TruthFixture) { printf("x = %d\n", x); } BOOST_FIXTURE_TEST_CASE(test_function, TruthFixture) { printf("f(2) = %d\n", f(2)); } then everything works perfectly as intended. Any input on what I am doing wrong with the *global* fixture declaration? Thank you! Mauricio Carneiro, Ph.D. http://www.broadinstitute.org/~carneiro/

[Please do not mail me a copy of your followup] Mauricio Carneiro <carneiro@gmail.com> spake the secret code <CAG0Owo1Qc15CqQMqHLAAmwv4UXPyn5ZW+kzrmkvVhv2srj5mxg@mail.gmail.com> thusly:
I am trying to use global fixtures in my tests but I may be misinterpreting the documentations.
Did you look here? <http://user.xmission.com/~legalize/boost.test/libs/test/doc/html/test/reference/test_case/boost_global_fixture.html>
The following toy example doesn't work :
Correct. The global fixture won't become the base class of your test cases. Use BOOST_FIXTURE_TEST_CASE to make a fixture the base class of a particular test case or BOOST_FIXTURE_TEST_SUITE to make a fixture the base class of all test cases in a suite. BOOST_GLOBAL_FIXTURE is for global setup/teardown where the c'tor runs before any test case and the d'tor runs after all test cases. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
participants (2)
-
legalize+jeeves@mail.xmission.com
-
Mauricio Carneiro