I would like to send an argument to a test fixture/suite. At the moment, the test suites that I am running look like:
CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry();
TestMessagingSystem is a suite that I have defined inside a fixture of the same name. Could I pass an argument to either the suite or the fixture? Preferably I would like to pass it to the fixture. The reason I need to do this is that I am running these tests using a middleware that requires the context from the main class to use some of it's functions. So I need to pass the context "down" to the individual tests. Is that possible?
That is not part of the API. Perhaps derive your own runner class from TextTestRunner and pass the parameter to the constructor or to a method that you add before making the runner.run() call.
If this is interesting to someone who has a similar question, here is what I did.
1. I defined the TestMessagingSystem suite without using the macros and instead something like:
CppUnit::Test* suite(cast::ManagedComponent* mcptr)
TestMessagingSystem::castMCPtr = mcptr;
CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite( "TestMessagingSystem" );
suiteOfTests->addTest( new CppUnit::TestCaller<TestMessagingSystem>(
&TestMessagingSystem::testPublishEOIMsgs ) );
Which means I overloaded the suite function. If someone is interested in the same, I used a static variable of the fixture to store the variable that I passed through.
2. Then in the main program, I didn't use the CPPUNIT_TEST_SUITE_REGISTRATION macro either. Instead, I did:
which means that I defined the fixture explicitly, also of name TestMessagingSystem. Then I called the suite inside and a passed an argument (which is the this pointer here).
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.