Boost logo

Boost Users :

Subject: [Boost-users] [Boost.Test] How to reuse test results?
From: Torri, Stephen CIV NSWCDD, W15 (stephen.torri_at_[hidden])
Date: 2010-09-09 11:24:40


I tried to use BOOST_FIXTURE_TEST_SUITE to use a fixture in multiple tests. Of course it works fine yet the behavior was not as I expected. What I was expecting which I learned from testing was that the fixture was setup and torn down on each test rather than when the suite ended. In my present problem I have a class which represents the initialization steps of an simulation. There are various algorithms that need to be executed and the results of one can be used in another. So what I was hoping to learn how to do is have a fixture which I can use in the tests of a suite which is only setup and torn down once respectively.
 
So something like:
 
#define BOOST_TEST_MODULE long_life_fixture
#include <boost/test/unit_test.hpp>
 
struct CommonData {
    CommonData() : i ( 0.0 ) { BOOST_TEST_MESSAGE("setup CommonData"); }
    ~CommonData() { BOOST_TEST_MESSAGE("tear down CommonData"); }
 
    double i;
};
 
BOOST_FIXTURE_TEST_SUITE ( class_tests, CommonData )
 
BOOST_AUTO_TEST_CASE ( function1_test )
{
     i = 5.0;
     BOOST_CHECK_EQUAL ( i, 5.0 );
}
 
BOOST_AUTO_TEST_CASE ( function2_test )
{
     double j = i * 5;
     BOOST_CHECK_EQUAL ( j, 25.0 );
}
 
BOOST_AUTO_TEST_SUITE_END()
 
Stephen
 
 
Stephen Torri, PhD
NAVAL SURFACE WARFARE CENTER DAHLGREN
17214 Ave B Suite 121
Dahlgren, Va. 22448
540-653-1082
I am not a contracting officer. I cannot modify or initiate contracts, nor do I have the authority to financially commit the government in any way.


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