Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top