Parameterizing a test using CppUnit

前端 未结 7 1434
情话喂你
情话喂你 2021-01-05 07:56

My organization is using CppUnit and I am trying to run the same test using different parameters. Running a loop inside the test is not a good option as any failure will abo

7条回答
  •  余生分开走
    2021-01-05 08:20

    class members : public CppUnit::TestFixture
    {
        int i;
        float f;
    };
    
    class some_values : public members
    {
        void setUp()
        {
            // initialization here
        }
    };
    
    class different_values : public members
    {
        void setUp()
        {
            // different initialization here
        }
    };
    
    tempalte
    class my_test : public F
    {
        CPPUNIT_TEST_SUITE(my_test);
        CPPUNIT_TEST(foo);
        CPPUNIT_TEST_SUITE_END();
    
        foo() {}
    };
    
    CPPUNIT_TEST_SUITE_REGISTRATION(my_test);
    CPPUNIT_TEST_SUITE_REGISTRATION(my_test);
    

    I don't know if that's considered kosher as per CppUnit's "preferred way of doing things" but that's the approach I'm taking now.

提交回复
热议问题