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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
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.