Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are examples of test suite property uses in CPPUnit? (CPPUNIT_TEST_SUITE_PROPERTY)

I joined a project where CPPUnit is used for unit testing and will be adding some tests that probably share setup and teardown code. In researching this more I came across

CPPUNIT_TEST_SUITE_PROPERTY

(from https://people.freedesktop.org/~mmohrhard/cppunit/group___writing_test_fixture.html)

Its description says

Adds a property to the test suite builder context.

http://cppunit.sourceforge.net/doc/cvs/group___writing_test_fixture.html says the following:

Adds a property to the test suite builder context

I am not sure what the expected use or purpose of that would be, though it appears like it could be useful for sharing common information, etc. I don't see examples of its use.

What is the value of this and are there some examples to point me to?

like image 432
Tim Avatar asked Feb 01 '17 17:02

Tim


1 Answers

According to this piece of code, it looks like you should be able to retrieve the property at some point while you are creating your test suite to pass it as a parameter to a specific test.

Maybe the goal was to allow you to do:

#define CPPUNIT_TEST_WITH_PARAM(testMethod,param) \
    CPPUNIT_TEST_ADD( new CppUnit::ParameterizedTestCase<ThisTestFixtureType>( \
                                        context.getTestNameFor( #testMethod ), \
                                        #testMethod, \
                                        &TestFixtureType::testMethod, \
                                        context.makeFixture(), \
                                        context.getStringProperty( param ) ) )

CPPUNIT_TEST_SUITE( MyTestSuite);
CPPUNIT_TEST_SUITE_PROPERTY( "param1", "foo" )
CPPUNIT_TEST_SUITE_PROPERTY( "param2", "bar" )
CPPUNIT_CPPUNIT_TEST_WITH_PARAM( func, "param1" )
CPPUNIT_CPPUNIT_TEST_WITH_PARAM( func, "param2" )
CPPUNIT_TEST_SUITE_END();

void func( const std::string& param ); 

And this would have ended calling func("foo") and func("bar"). Which would be nice because it would have made it possible to add string parametrized tests.

However, and this is just a guess attempt, as ParameterizedTestCase is not part of 1.12.1 old release, nor is it part of more recent releases (so does CPPUNIT_TEST_ADD macro), I believe this is apparently something that was in a release plan but aborted and the macro CPPUNIT_TEST_SUITE_PROPERTY remains useless here. The getStringProperty also remains, and I found no way it could be used properly.

To conclude, this looks like a broken stuff and was anyway apparently not meant to share setup/teardown code, but more to have parametrized tests (which can be done by templates actually, see this post).

like image 174
jpo38 Avatar answered Nov 11 '22 05:11

jpo38