2

I have two test classes called "TT_Common" and "TT_Container" which extends CPPUNIT_NS::TestFixture:

class TT_Common : public CPPUNIT_NS::TestFixture ...... class TT_Container : public CPPUNIT_NS::TestFixture ...... 

And anoter class called TT_Runner which extends CPPUNIT_NS::TestRunner:

class TT_Runner : public CPPUNIT_NS::TestRunner { ..... void run( CPPUNIT_NS::TestResult &controller, const std::string &testPath ) { CPPUNIT_NS::TestPath path = m_suite->resolveTestPath( testPath ); CPPUNIT_NS::Test *testToRun = path.getChildTest(); for ( size_t iIdx = 0; iIdx < testToRun->getChildTestCount(); iIdx++ ) { CPPUNIT_NS::Test* psTest = testToRun->getChildTestAt(iIdx); std::string testName = psTest->getName(); // testName is TT_Common for iIdx = 0 and TT_Container for iIdx = 1 } } 

I already have the name of the TestFixture but how to create a Instace of it? I can't find a factory or registry which takes the name and return a instance.

4
  • 1
    Why do you want to instantiate a fixture manually? Fixtures are base classes for the tests. They may not do anything useful on their own. Commented Jan 25, 2012 at 9:02
  • I want to create multiple object of type TT_Common and TT_Container using its name to start the functions in context of these objects in multiple threads. Commented Jan 25, 2012 at 9:15
  • The tests will be automatically run in context of appropriate fixtures (each test in new instance). I still don't see why you should do it manually. Commented Jan 25, 2012 at 10:57
  • I want to have one instance for all test functions (some functions will depend on other functions). And for each Thread i need one of those instances. Commented Jan 25, 2012 at 12:54

1 Answer 1

3

It's not how fixtures work and not how tests work. A fixture is instantiated for each test separately, so the tests are isolated. And the tests are run in unspecified order, so they must not depend on each other.

Normally when you have functions that depend on each other, you just have a long test case that calls them all. If you want anything else, you really have to do it manually outside of cppunit.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right, usually test functions should not depend on other functions. I already have a self-written test environment which allows me to specify which function I want to call using XML (function order, call times, parameters, etc...). And I already have some test projects in CPPUnit. I try to enable these feature in my CPPUnit projects so that I have one test environment instead of two.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.