Search code examples
c++testingboostbuild

Compiling Boost.Test tests faster


I am using xcode (gcc) to compile my boost test suite and it takes too long.

The tests are minimal dummy tests, yet it takes several seconds (about 20) to compile them:

#include "boost/test/included/unit_test.hpp"

BOOST_AUTO_TEST_CASE(dummy)
{
    BOOST_CHECK_EQUAL(2+2, 4);
}

BOOST_AUTO_TEST_CASE(dummyFail)
{
    BOOST_CHECK_EQUAL(2+3, 4);
}

The manual suggests using the library version to speed up compilation. However, I am concerned this might not work - xcode already rebuilds my tests only. The whole framework isn't compiled again since the object files exist.

I guess it's the amount of header files and templates in Boost.Test that are responsible for most of the compilation time.

Do you have an idea of how to compile significantly faster? Would using it as library work? Would including only parts of boost.test work?

Any help is greatly appreciated!


Solution

  • The reason it's slow to compile is because boost/test/included/unit_test.hpp is huge. Using a library makes it faster because the huge header is compiled when the library is built and not thereafter. Your tests then include a smaller set of headers, leading to shorter build times.

    Because I'm too lazy to build the library, an alternative I've used is to have one source file (which never changes, and so is rarely rebuilt) include the full boost test, and then have all the real test sources include just boost/test/unit_test.hpp. That gives most of the benefits of using the library.