#39 parameterized fixture

open
nobody
5
2014-02-26
2004-12-24
xaliphostes
No

It would be nice if each test of a fixture can be
parameterize (with an xml formatting string for example).

That way, for a same fixture plugin, we can run it
several times with different parameters.

Discussion

  • fussel4711
    fussel4711
    2014-02-26

    I've implemented some macros aiding to define parameterized CppUnit tests.

    With this solution you just need to replace the old macros CPPUNIT_TEST_SUITE and CPPUNIT_TEST_SUITE_END within the class's header file:

    CPPUNIT_PARAMETERIZED_TEST_SUITE(<TestSuiteClass>, <ParameterType>);
    /*
     * Put plain old tests here.
     */ 
    CPPUNIT_PARAMETERIZED_TEST_SUITE_END();
    

    In the implementation file you need to replace the old CPPUNIT_TEST_SUITE_REGISTRATION macro with:

    CPPUNIT_PARAMETERIZED_TEST_SUITE_REGISTRATION (<TestSuiteClass>, <ParameterType>)
    

    These macros require you to implement the methods:

    static std::vector parameters();
    void testWithParameter(ParameterType& parameter);
    
    • parameters(): Provides a vector with the parameters.
    • testWithParameter(...): Is called for each parameter. This is where you implement your parameterized test.

    A detailed explanation can be found here: http://brain-child.de/engineering/parameterizing-cppunit-tests

    The german version can be found here: http://brain-child.de/engineering/parametrierbare-tests-cppunit


    I would appreciate if the CppUnit team will integrate my work into the CppUnit framework. In this case it would be nice if you mention the source within the source code and documentation ;)