I'm finding that auto-registration isn't working for me, even though I seem to be following all the guidelines and have doubled checked my work. Here's my problem with an example test setup.
[
(SchedulerTestCase.cpp)
class SchedulerTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SchedulerTest);
CPPUNIT_TEST(justWait);
...
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SchedulerTest, componentSuiteName());
]
It seems to me that MSVC++is optimising out the creation of statics in the particular module until there is some direct code reference (via the exported suite function). I have tried tweaking compiler options (we're using Multithread DLL libraries), to no avail.
Help ? I can provide more information if required.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So your test runner is in the app, and the DLL has the test fixtures? (Never derived from fixture myself, always TestCase. Don't know the difference.)
Most compilers have ways to turn off dead-code stripping, and I'm sure that MSVC does, I just don't know what it is. In CodeWarrior it's #pragma force_active on|off|reset. Maybe the MSDN docs can help you out there.
(The way I've tested DLLs was to define a Test export and just call that if it exists, but obviously that leads to a lot of duplicated Test() routines that could be pulled into the host app. I just never wanted to tackle the stripping issue.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm finding that auto-registration isn't working for me, even though I seem to be following all the guidelines and have doubled checked my work. Here's my problem with an example test setup.
[
(SchedulerTestCase.cpp)
class SchedulerTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SchedulerTest);
CPPUNIT_TEST(justWait);
...
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SchedulerTest, componentSuiteName());
]
[
(unit_test.cpp)
CPPUNIT_REGISTRY_ADD_TO_DEFAULT( componentSuiteName() );
...
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
]
This just doesn't work.
What does work is this `hack`, causing the tests to be added _twice_ (once through the registry, and a second time via the explicit addTest).
[
(in SchedulerTestCase.cpp)
CPPUNIT_NS::TestSuite* SchedulerTestSuite()
{ return SchedulerTest::suite(); }
]
[
(in unit_test.cpp)
extern CPPUNIT_NS::TestSuite* SchedulerTestSuite();
...
runner.addTest( SchedulerTestSuite() );
]
It seems to me that MSVC++is optimising out the creation of statics in the particular module until there is some direct code reference (via the exported suite function). I have tried tweaking compiler options (we're using Multithread DLL libraries), to no avail.
Help ? I can provide more information if required.
So your test runner is in the app, and the DLL has the test fixtures? (Never derived from fixture myself, always TestCase. Don't know the difference.)
Most compilers have ways to turn off dead-code stripping, and I'm sure that MSVC does, I just don't know what it is. In CodeWarrior it's #pragma force_active on|off|reset. Maybe the MSDN docs can help you out there.
(The way I've tested DLLs was to define a Test export and just call that if it exists, but obviously that leads to a lot of duplicated Test() routines that could be pulled into the host app. I just never wanted to tackle the stripping issue.)