2

我有两个名为“ TT_Common ”和“ TT_Container ”的测试类,它们扩展了 CPPUNIT_NS::TestFixture:

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

另一个名为 TT_Runner 的类扩展了 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
   }
 }

我已经有了TestFixture 的名称,但是如何创建它的实例?我找不到采用名称并返回实例的工厂或注册表。

4

1 回答 1

3

这不是固定装置的工作方式,也不是测试的工作方式。为每个测试单独实例化一个夹具,因此测试是隔离的。并且测试以未指定的顺序运行,因此它们不能相互依赖。

通常,当您有相互依赖的函数时,您只有一个很长的测试用例来调用它们。如果你想要其他任何东西,你真的必须在 cppunit 之外手动完成。

于 2012-01-25T14:21:51.543 回答