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

1

7

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?

Earlearla answered 1/2, 2017 at 17:35 Comment(0)
E
4

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).

Envelop answered 9/2, 2017 at 8:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.