Using Boost Unit Test Framework (UTF) with `make check`

My C ++ application has various shell-based integration tests for stand-alone programs, as well as unit code tests for the application API. Tests are run through the make check target generated using Autotools (autoconf, automake), which come with a test driver and a log parser . I started using the Boost Unit Test Framework to better manage Unit Test kits. Is there a way to run both acceptance tests and unit tests (using both Boost UTF and standard TAP tests) as part of a 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 is as follows:

 #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(); 
+6
source share
2 answers

If you use boost-m4 like me, 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 more elegant than directly placing "-lboost_unit_test_framework" inside your Makefile.am. You can also consider moving '#define BOOST_TEST_DYN_LINK' from your cpp to AM_CPPFLAGS to Makefile.am, as shown above.

See boost-m4 README for more information.

+2
source

The standard way to handle this is not to use the primary bin fields, but the primary TEST. In your case, your Makefile.am will look something like this:

  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) 

Check this answer for more info.

+1
source

Source: https://habr.com/ru/post/944014/


All Articles