Re: [Cppunit-devel] cppunit tests from config file
Brought to you by:
blep
|
From: CppUnit d. m. l. <cpp...@li...> - 2006-10-25 21:10:14
|
C++ does not support reflection. The only way to refer to a method is by=20
using explicitly its name inside the code, like in your example.
The most elegant way to do this is to use the CPPUNIT macros :
class CMyTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(CMyTest);
CPPUNIT_TEST(test1);
CPPUNIT_TEST(test2);
CPPUNIT_TEST_SUITE_END();
private:
void test1();
void test2();
};
CPPUNIT_TEST_SUITE_REGISTRATION(CMyTest);
This will generate some kind of CppUnit-specific reflection, so one can=20
later refer to the methods by name :
CPPUNIT_NS::TestRunner runner;
CPPUNIT_NS::TestFactoryRegistry& registry =3D=20
CPPUNIT_NS::TestFactoryRegistry::getRegistry();
CPPUNIT_NS::Test* pAllTests =3D registry.makeTest();
...
runner.addTest(pAllTests);
runner.run(result, "CMyTest::test2"); // Referred by name as string
Vincent Rivi=E8re.
|