简体   繁体   中英

Boost.Test howto create “test dependency”

I'm using boost.test as test suite. I want to know if is possible make some prerequisite for test. For example

uniqut_ptr< MyClass > g_class;

BOOST_AUTO_TEST_CASE( test1 )
{
    BOOST_REQUIRE_NO_THROW( g_class = CreateMyClass() );
}

BOOST_AUTO_TEST_CASE( test2 )
{
    // This test need the test1 as passed
    BOOST_REQUIRE( g_class->doSomething() );
}

In this case if test1 fail program will crash in test2. I know that I can add BOOST_REQUIRE( g_class ) at the begining of each test. But is there another way?

I see the boost REQUIRE for use when you require something to be true, so put the require at the top of each test. Or consider using a test fixture and do the setup in the setup function. There are examples here It smells like you are trying to use a global variable in your test, so they might interact in horrible ways. Global data is more trouble than it's worth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM