What are some examples of using test suite properties in CPPUnit? (CPPUNIT_TEST_SUITE_PROPERTY)

I joined a project in which CPPUnit is used for unit testing and will add some tests that are likely to have setup and break code. Studying 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 set builder context.

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

Adds a property to the test case linker context.

I am not sure what the expected use or purpose of this will be, although it appears as if it could be useful for sharing general information, etc. I do not see examples of its use.

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

+7
c ++ unit-testing cppunit
source share
1 answer

According to this piece of code , it looks like you should get the property at some point while you create your test in order to pass it as a parameter for a specific test.

Perhaps the goal was to let you 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 that would end up calling func("foo") and func("bar") . Which would be nice, because it would add parameterized string tests.

However, this is just an attempt to guess , since ParameterizedTestCase not part of the old version 1.12.1 and is not part of the latest releases (so the macro CPPUNIT_TEST_ADD ), I think that this is apparently something that was in terms of release but interrupted, and the macro CPPUNIT_TEST_SUITE_PROPERTY is useless here. getStringProperty also remains, and I did not find a way to use it correctly.

In conclusion, it looks like broken material and, in any case, apparently, is not intended to share the setup / break code, but moreover, to have parameterized tests (which can actually be done using the templates, see this post ).

+4
source share

All Articles