문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top