I'd encountered a problem with a particular way I'd set up a test application where some
BOOST_AUTO_TEST_CASE functions would be executed while others wouldn't. I suspect this
may be Visual Studio (2005) specific.
I've got a work-around, which I thought might help others in the same situation.
The scenario is this -
Main test application: testapp.cpp -
#define BOOST_AUTO_TEST_MAIN "TestApp for some Lib"
#include
BOOST_AUTO_TEST_CASE(IGetExecutedByTestFramework)
{
BOOST_CHECK(false);
}
External library, containing: somemodule_tests.cpp -
#include "somemodule.h"
#include
//Test functionality provided by somemodule.h
//...
BOOST_AUTO_TEST_CASE(IDontGetExecuted)
{
BOOST_CHECK(false);
}
My Visual Studio solution contains two projects -
- mylibtestapp: A console executable to run all test cases in mylib
Contains only testapp.cpp
- mylib: A statically linked lib containing a bunch of .cpp/.h
files and, so far, just one ..._tests.cpp file.
The solution is set up so that mylibtestapp depends on mylib. It
also explicitly links with the boost 'unit_test_framework.lib'.
It compiles and links fine.
When running, only the 'IGetExecutedByTestFramework' gets executed.
I manually expanded the BOOST_AUTO_TEST_CASE macro for
'IDontGetExecuted' and the debugger wouldn't step into any of the
test registrar object constructor code, so I assume the linker
decided to strip out the code for some reason.
As soon as I added the following to somemodule_tests.cpp -
int g_fiddle;
and change testapp.cpp to 'extern int g_fiddle;' and manually insert
the 'init_unit_test_suite(int argc, char* argv[])' with some trivial
use of 'g_fiddle' (using it in a printf), then both test cases get
executed.
After poking around with the linker options little further, I've
found that all unit tests will run as originally intended, without
having to use any extern frigs, so long as the mylibtestapp's
'Configuration Properties'>Linker>General>'Use Library Dependency
Inputs' is set to 'Yes'. The difference being that the linker
command-line now contains mylib.lib instead of the individual .o
files of mylib.
Weird.
--
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.12/655 - Release Date: 28/01/2007 13:12