我有两个名为“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 的名称,但是如何创建它的实例?我找不到获取名称并返回实例的工厂或注册表。
最佳答案
这不是装置如何工作的,也不是测试如何工作的。为每个测试单独实例化一个装置,因此测试是隔离的。并且测试以未指定的顺序运行,因此它们不能相互依赖。
通常,当您拥有相互依赖的函数时,您只需一个很长的测试用例来调用它们。如果您想要其他任何东西,您确实必须在 cppunit 之外手动完成。
关于c++ - CPPUNIT:如何使用名称创建 TestFixture 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8999790/