boost.test and independent compilation/running of tests
Hi,
I'm trying to figure out what the best way to use boost.test to achieve
something close to TDD (test driven development) is; I should presumably also
mention that I'm using qmake and not bjam as a build utility.
I've managed to build and use boost.test fine (after figuring out that I
needed to add -DBOOST_TEST_DYN_LINK), but what I haven't been able to achieve
is to
a) have several smaller test-cases/suites for TDD so that I can rapidly
recompile and run a small subset of tests whilst I'm developing a specific
class.
b) have one big test-suite, integrating all the above, for regression testing
to be run periodically (after the above subset of tests passed; on svn
commit etc.)
I haven't figured out how to set things up so that I can compile individual
tests to .o files and then either simply build a complete regression suite
executable from them or an executable from just one (or a few) of these tests;
because I don't know how to use the autoregistration facilities without ending
up with multiple main()s.
My test files currently look something like this:
//file foo_test.cpp
#define BOOST_TEST_MODULE foo_test
#include
"Alexander Schmolck"
Hi,
I'm trying to figure out what the best way to use boost.test to achieve something close to TDD (test driven development) is; I should presumably also mention that I'm using qmake and not bjam as a build utility.
I've managed to build and use boost.test fine (after figuring out that I needed to add -DBOOST_TEST_DYN_LINK), but what I haven't been able to achieve is to
a) have several smaller test-cases/suites for TDD so that I can rapidly recompile and run a small subset of tests whilst I'm developing a specific class.
b) have one big test-suite, integrating all the above, for regression testing to be run periodically (after the above subset of tests passed; on svn commit etc.)
I haven't figured out how to set things up so that I can compile individual tests to .o files and then either simply build a complete regression suite executable from them or an executable from just one (or a few) of these tests; because I don't know how to use the autoregistration facilities without ending up with multiple main()s.
My test files currently look something like this:
//file foo_test.cpp #define BOOST_TEST_MODULE foo_test #include
#include "foo.h" // Test Suite BOOST_AUTO_TEST_SUITE(foo_test_suite); BOOST_AUTO_TEST_CASE(some_test_case) { // ... } BOOST_AUTO_TEST_SUITE_END();
What's the recommended way to go about this?
Define BOOST_TEST_MODULE only in single file of your multi-file test module. HTH, Gennadiy
"Gennadiy Rozental"
I haven't figured out how to set things up so that I can compile individual tests to .o files and then either simply build a complete regression suite executable from them or an executable from just one (or a few) of these tests; because I don't know how to use the autoregistration facilities without ending up with multiple main()s. [...] Define BOOST_TEST_MODULE only in single file of your multi-file test module.
Thanks for the help. I guess that means that I'm going to setup things so that
I have a single run_tests.cpp that just looks like so:
#define BOOST_TEST_MODULE test_everything
#include
"Alexander Schmolck"
"Gennadiy Rozental"
writes: I haven't figured out how to set things up so that I can compile individual tests to .o files and then either simply build a complete regression suite executable from them or an executable from just one (or a few) of these tests; because I don't know how to use the autoregistration facilities without ending up with multiple main()s. [...] Define BOOST_TEST_MODULE only in single file of your multi-file test module.
Thanks for the help. I guess that means that I'm going to setup things so that I have a single run_tests.cpp that just looks like so:
#define BOOST_TEST_MODULE test_everything #include
Yes. You can do this.
and only vary the make target; i.e. what I link against it (just a single/few test-file(s) during development or the complete regression suite). Does this sound sensible?
Yes it's reasonable.
Another option might be to always build the complete regression test and then pass a string/regexp on the commandline to specify what suite/testcase(s) to run, but as far as I can tell that isn't yet supported out of the box, and would likely require more work than above approach, right?
Yes. It's available already in my local copy. Once I am finished with docs I'll try to commit it into source control (I have to setuo this one as well)
Also, from reading the docs I get the impression that it isn't (easily) possible to span tests suites over multiple files, unless one forgoes the convenience of BOOST_AUTO_TEST_CASE/SUITE -- e.g.. I can't just use
//file1.cpp BOOST_AUTO_TEST_SUITE(foo_suite) [...] BOOST_AUTO_TEST_SUITE_END()
//file2.cpp BOOST_AUTO_TEST_SUITE(foo_suite) [...] BOOST_AUTO_TEST_SUITE_END()
to automagically either add more tests to foo_suite or create it if it hasn't been previously defined?
It's been requested recently and I implemented this as well in my local copy. Keep an eyes open for commit ;) Gennadiy
participants (2)
-
Alexander Schmolck
-
Gennadiy Rozental