How do I get BOOST_TEST_MESSAGE to display on the screen?
Asked Answered
P

1

18

I'm fumbling my way through the Boost Unit Testing Framework and have set up a basic functioning unit test. I'm using BOOST_TEST_MESSAGE to let the user know which tests are running, but the messages don't display on the screen. For example:

#define BOOST_TEST_MODULE MyTest

#include <boost/test/included/unit_test.hpp>

BOOST_FIXTURE_TEST_SUITE(MyTestSuite, MyTestFixture)

BOOST_AUTO_TEST_CASE(MessageTest)
{
  BOOST_TEST_MESSAGE( "no one sees this!" );
}

BOOST_AUTO_TEST_SUITE_END();

I have tried defining BOOST_TEST_LOG_LEVEL to all but this has no effect. I got that idea from the Boost log-level parameter page, but I think the concept of the log might not be related to what is actually displayed on the screen. Any ideas?

Print answered 20/10, 2013 at 1:19 Comment(2)
Did you try <program-name> --log_level=message?Shotton
putenv("BOOST_TEST_LOG_LEVEL=message") in main(), works too.Thematic
S
17

As per the documentation:

Messages generated by this tool do not appear in test log output with default value of the active log level threshold. For these messages to appear the active log level threshold has to be set to a value below or equal to "message".

Either set the environment variable BOOST_TEST_LOG_LEVEL to message when running your test binary:

BOOST_TEST_LOG_LEVEL=message <your_test>

or pass the command line argument --log_level:

<your_test> --log_level=message
Stack answered 13/11, 2014 at 14:15 Comment(2)
Where to put this code? I put it in the test case BOOST_TEST_LOG_LEVEL = message <testcase1>, but it doesn't compile.Verity
@Verity as mentioned, you need to export this as an environment variable in your terminal.Stack

© 2022 - 2024 — McMap. All rights reserved.