Menu

Running single testsuite

Help
sanrao
2007-01-08
2013-04-22
  • sanrao

    sanrao - 2007-01-08

    Hi,
       Pls explain, how to execute a single test from registry inspite of registering multiple test suites. How is the argv[] variable given to the main() passed to the test "getregistry().maketest();"

    Kindly reply asap!!

    Thank you,
    Regards
    Santhosh

     
    • TrickiDicki

      TrickiDicki - 2007-08-02

      I couldn't find anything in the FAQs or documentation, so a bit of digging and experimentation I found a way to do it.
      You can pass in an argument to the getRegistry() method, so here I pass in the command-line argument if one were provided:

      int main(int argc, char* argv[])
      {
        // Get the top level suite from the registry
        CPPUNIT_NS::Test *suite = CPPUNIT_NS::TestFactoryRegistry::getRegistry( argc == 2 ? argv[1] : "All Tests" ).makeTest();

      ...

      This will create only the named test suite. How do you name a test suite? Like this:

      CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MyClass_test, "MyClass" );

      So now in my project settings, I give the command-line argument "MyClass" and it only runs that one test. If I remove the cmd-line arg, all tests are run.

      Bingo!

      Cheers

      - R

       
    • TrickiDicki

      TrickiDicki - 2007-08-02

      OK, it turns out it's not quite as simple as that, but it's not too hard either.

      You have to register the test both as a named test and as a default test, so your registration code looks like this:

      CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MyClass_test, "MyClass" );
      CPPUNIT_TEST_SUITE_REGISTRATION( MyClass_test );

      Why the named registration doesn't register it as default also I have no idea. Double the code, double the fun??!!

      Hope that helps

      - R

       

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.