How to run subset of unit tests in CPPUnit by selecting them at run-time?

后端 未结 3 733
野趣味
野趣味 2021-01-12 13:53

I am using CppUnit as a unit test framework. Is it possible to select a subset of testcases to execute at runtime?

Is there a filtering option provided within CppUn

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-12 14:58

    An alternative approach:

    // find the unit test as specified by the one argument to this program
    CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
    int iTestIndex = 0;
    for (; iTestIndex < suite->getChildTestCount(); ++iTestIndex)
    {
        fprintf(stderr, "INFO: Looking for a match between '%s' and '%s'\n",
                suite->getChildTestAt(iTestIndex)->getName().c_str(),
                argv[1]);
        if (suite->getChildTestAt(iTestIndex)->getName() == std::string(argv[1]))
        {
            fprintf(stderr, "INFO: Found a match for '%s' and '%s'\n",
                    suite->getChildTestAt(iTestIndex)->getName().c_str(),
                    argv[1]);
            break;
        }
    }
    if (iTestIndex >= suite->getChildTestCount())
    {
        fprintf(stderr, "ERROR: Did NOT find test '%s'!\n", argv[1]);
        return -1;
    }
    

提交回复
热议问题