Using The Boost Unit Test Framework (UTF) with `make check`
Asked Answered
C

2

6

My C++ application has various shell-based integrations tests for standalone programs as well as source code unit tests for the app's API. The tests are run through the make check target, generated through Autotools (autoconf, automake), which come with a test-driver and a log parser. I've started adopting the Boost Unit Test Framework for better management of unit test suites. Is there a way to run both the acceptance tests and unit tests (using both the Boost UTF and standard TAP tests) under the make check target?

My Makefile.am looks something like this:

check_PROGRAMS = test1 test2
SOURCES = test1.cpp test2.cpp
CC = g++
TESTS = $(check_PROGRAMS) standalone1.test standalone2.test
LDADD = -lboost_unit_test_framework
TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
    $(top_srcdir)/test/tap-driver.sh
EXTRA_DIST = $(TESTS)

The Boost UTF test suite looks like this:

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "My Unit Tests"

#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE(MyTestSuite1);
    BOOST_AUTO_TEST_CASE(MyTestCase1) {
        BOOST_CHECK(true);
    }
BOOST_AUTO_TEST_SUITE_END();
Commutation answered 1/5, 2013 at 1:32 Comment(0)
B
2

If you are using boost-m4 like I do, you can try:

./configure.ac:

BOOST_REQUIRE([1.61])
BOOST_SYSTEM
BOOST_TEST

./test/Makefile.am (add AM_CPPFLAGS, AM_LDFLAGS and LDADD)

AM_CPPFLAGS = $(BOOST_CPPFLAGS) -DBOOST_TEST_DYN_LINK
AM_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_SYSTEM_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LDFLAGS)
LDADD = $(BOOST_SYSTEM_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS)

check_PROGRAMS = test1 test2
SOURCES = test1.cpp test2.cpp
CC = g++
TESTS = $(check_PROGRAMS) standalone1.test standalone2.test
EXTRA_DIST = $(TESTS)

This seems to be more elegant than directly putting '-lboost_unit_test_framework' inside your Makefile.am. You may also consider moving '#define BOOST_TEST_DYN_LINK' from your cpp to AM_CPPFLAGS in Makefile.am as shown above.

For more details, refer to boost-m4 README

Broncho answered 11/8, 2016 at 8:46 Comment(0)
E
1

The standard way to deal with it is not using bin primaries but the TEST primary. In your case your Makefile.am would look something like:

 LDADD = -lboost_unit_test_framework

 TESTS = standalone1 standalone2 
 standalone1_SOURCES = test1.cpp standalone1.test
 standalone2_SOURCES = test2.cpp standalone2.test

TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
                  $(top_srcdir)/test/tap-driver.sh
EXTRA_DIST = $(TESTS)

For more info check this answer

Expire answered 14/4, 2015 at 4:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.