Menu

how to get test name in setUp() method

Help
Anonymous
2003-04-17
2003-06-09
  • Anonymous

    Anonymous - 2003-04-17

    I tried getName() and toString() function but it didn't work.

    getName() returns the name of TestSuite, if one defined. null otherwise.

    toString() returns name of the TestCase/TestSuite class.
    Any ideas? how can I get the name of the CPPUNIT_TEST?

    Thanks,
    Kiran.

     
    • Hisakuni Kitahara

      I'm not sure it works on your env, but try follows.
      My env is solaris 5.7 and cppunit-1.8.0

      [add 2 static vals to your test suite]
      class YourTest : public CppUnit::TestFixture {
          CPPUNIT_TEST_SUITE(YourTest);
          CPPUNIT_TEST(testNo1);
                         ・
                              ・
           CPPUNIT_TEST_SUITE_END();
      private:
      // vector for all test
      static const vector<CppUnit::Test *> &msTests;
      // index for current test case
      static int     msTestNo;

      [initialize the static vals as follows]
      const vector<CppUnit::Test *>
           YourTest::msTests = suite()->getTests();

      int YourTest::msTestNo = 0;

      [add increment in the tearDown()]
      virtual void tearDown(){
          ++msTestNo;
      }

      Now you can get test name from
      msTests[msTestNo]->getName();

      function returns like "YourTest.testXXXXX".

      I hope it'll works on your env,
      Hisa.

       

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.