I would like to organize all unit tests into a lib, and then create 2 executables that link to the unit test lib:
- GUI Test runner (like HostApp example)
- text version to run all tests on the command line
The unit tests use the new macros introduced in cppunit 1.5.5.
As a proof of concept, I moved ExampleTestCase.[h,cpp]into a separate lib, then attempted to link HostApp to the new lib. Running HostApp fails to find the tests defined in ExampleTestCase.
Can some one explain why this doesn't work and how
I could get it to work? It may assist if there was
a sample of this in the examples directory.
Environment is VC++ 6.0, SP4.
Ralph Bohnet
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The library and the executable have different "static space". TestFactory registry use a static singleton. So the library have its one singleton and the executable have another one.
The way around this is to get the library to publish its test suite:
CppUnit::Test *getLibrarySuite()
{
CppUnit::TestSuite *suite = new CppUnit::TestSuite( "My library test" );
TestRegistry.getRegistry().addTestToSuite( suite );
return suite;
}
I would like to organize all unit tests into a lib, and then create 2 executables that link to the unit test lib:
- GUI Test runner (like HostApp example)
- text version to run all tests on the command line
The unit tests use the new macros introduced in cppunit 1.5.5.
As a proof of concept, I moved ExampleTestCase.[h,cpp]into a separate lib, then attempted to link HostApp to the new lib. Running HostApp fails to find the tests defined in ExampleTestCase.
Can some one explain why this doesn't work and how
I could get it to work? It may assist if there was
a sample of this in the examples directory.
Environment is VC++ 6.0, SP4.
Ralph Bohnet
The library and the executable have different "static space". TestFactory registry use a static singleton. So the library have its one singleton and the executable have another one.
The way around this is to get the library to publish its test suite:
CppUnit::Test *getLibrarySuite()
{
CppUnit::TestSuite *suite = new CppUnit::TestSuite( "My library test" );
TestRegistry.getRegistry().addTestToSuite( suite );
return suite;
}
The implementation must not be in a header file.
You add the library test as follow in executable:
TestRunner runner;
runner.addTest ( getLibrarySuite() );