Menu

Obtaining suite name in main()

Help
mrbob2
2007-04-18
2013-04-22
  • mrbob2

    mrbob2 - 2007-04-18

    How can I obtain the name of the suite that is being run in my main() function?  When I do a getName() on my suite it only returns "All Tests".  I need to be able to get the name of the suite that is being run so that I can generate a unique report name for it.  I have been looking all through the API docs and can't seem to find a way to do this.  Any ideas?  Here is my main function:

    int main (int argc, char* argv[])
    {
        // informs test-listener about testresults
        CPPUNIT_NS :: TestResult testresult;

        // register listener for collecting the test-results
        CPPUNIT_NS :: TestResultCollector collectedresults;
        testresult.addListener(&collectedresults);

        // Add a listener that print dots as test run.
        CPPUNIT_NS::BriefTestProgressListener progress;
        testresult.addListener(&progress);

        // insert test-suite at test-runner by registry
        CPPUNIT_NS::TextTestRunner testrunner;
        CPPUNIT_NS::Test* suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest();
       
        testrunner.addTest(suite);
        testrunner.run(testresult);

        // output results in compiler-format
        CPPUNIT_NS :: CompilerOutputter compileroutputter (&collectedresults, CPPUNIT_NS::stdCOut());
        compileroutputter.write();

        // output results into xml format
        std::fstream outputFile( (char *)strTestRptFilePath.c_str(), std::ios::out);
        CPPUNIT_NS :: XmlOutputter xmloutputter (&collectedresults, outputFile);
        xmloutputter.write();
       
        // return 0 if tests were successful
        return collectedresults.wasSuccessful () ? 0 : 1;
    }

     
    • Pascal Fleury

      Pascal Fleury - 2007-04-19

      The suite itself is produced by makeTest(), so it cannot infer a meaningful short name, hence the 'All Tests'.
      You could print all test names with this:

      void print_all_tests(Test* t) {
          cerr << t->getName() << endl;
          for (int i=0; i < t->getChildTestCount(); i++)
              print_all_tests( t->getChildTestAt(i) );
      }

      and see if there is another name down the tree that may suit your reporting better.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.