Menu

TextTestRunner with TestSuite

Anonymous
2002-03-14
2002-03-28
  • Anonymous

    Anonymous - 2002-03-14

    When I add a TestSuite to a TextTestRunner, I get s seg fault after the tests run.   This does not happen if I add TestCallers instead.

    Am I doing something wrong here?

    I am running Mandrake Linux 8.1
    gcc version 2.96 20000731

    -----------------------------------

    #include <cppunit/TestCase.h>
    #include <cppunit/TestCaller.h>
    #include <cppunit/TestSuite.h>
    #include <cppunit/TestResult.h>
    #include <cppunit/TextTestRunner.h>
    #include <ostream.h>

    class MyTest : public CppUnit::TestCase  {
    private:
     
    public:
      void setUp ()  {}
      void tearDown ()  {}

      void testOne ()  {}
      void testTwo ()  {}
    };

    int
    main()
    {
      CppUnit::TestSuite suite;
      CppUnit::TestResult result;
      suite.addTest (new CppUnit::TestCaller<MyTest>("testOne", &MyTest::testOne));
      suite.addTest (new CppUnit::TestCaller<MyTest>("testTwo", &MyTest::testTwo));

      CppUnit::TextTestRunner runner;

      // commneting out the next line and
      // uncommenting the following two makes
      // the problem go away.

      runner.addTest (&suite);
      //runner.addTest (new CppUnit::TestCaller<MyTest>("testOne", &MyTest::testOne));
      //runner.addTest (new CppUnit::TestCaller<MyTest>("testTwo", &MyTest::testTwo));

      runner.run ();
    }

     
    • Anonymous

      Anonymous - 2002-03-14

      The example I posted seems to work for me now.
      I will try again to reproduce the problem.
      Sorry.

       
    • Baptiste Lepilleur

      From the doc:
      - The test runner manage the life cycle of the added tests.

      => that means after running the test, the test runner will delete the suite.

      You must instantiate your suite with new TestSuite().

      Baptiste.

       

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.