1

I wrote some simple boost tests. The test compiles, but starting it does not execute the test body. Below is an example of a test.

// Windows uses Boost static libraries
#ifndef _WIN32
    #define BOOST_TEST_DYN_LINK
#endif

#define BOOST_TEST_MODULE "SimpleTest"

#include <boost/test/unit_test.hpp>

#include "radarInterface/ObjConfiguration.h"
#include "radarInterface/ObjIF.h"
#include "CommonFunctions.h"

#ifndef BOOST_TEST
    #define BOOST_TEST(A)
#endif

BOOST_AUTO_TEST_SUITE(_obj_interface_)

BOOST_AUTO_TEST_CASE(init_string)
{
    BOOST_TEST_MESSAGE("init_string");

    ObjConfiguration conf;

    conf.mcastAddress("225.0.0.40");
    conf.mcastPort(6310);
    conf.ipAddress("127.0.0.1");
    conf.tcpPort(6312);

    BOOST_TEST(conf.isComplete() == true);

    ObjIF objIf;

    BOOST_CHECK_NO_THROW(objIf.init(conf));

    usleep(3000000);
    ri.fini();
}

BOOST_AUTO_TEST_SUITE_END()

Trying to run it looks like everything is fine but in truth the test body is not running. I use CMake to compile and run tests. The following is the result of running the tests with CMake (ctest) after their compilation.

  Test project C:/Users/kongrosian/SimpleTest/build
      Start 1: ObjInterface_test
  1/1 Test #1: ObjInterface_test ..............   Passed    0.03 sec

  100% tests passed, 0 tests failed out of 1

  Total Test time (real) =   0.05 sec

Even running it from the command line doesn't seem to work. Using the command

".\ObjInterface_test.exe --log_level=message --run_test=init_string"

I would expect to see at least the "init string" message. Instead I simply get

Process PID: xxxx

If I use the test code written in the comments by sehe in my project the result is the same. When executing commands

./sotest --log_level=message --run_test=_obj_interface_/init_string

or

./sotest --list_content

I get Process PID: xxxx as command line output.

Do you have any ideas on why this behavior? The boost version I'm using is 1.72.

I hope I have clarified better.

coman
  • 11
  • 4
  • What tool gives you the output (starting with "Test project C:/Users/kongrosian/SimpleTest/build")? I don't recognize that as Boost Test. It might be some other testing framework. Perhaps your IDE is opinionated and presupposes CTest/Gtest or or something like that. In that light, can you describe what build tools / IDE environment you're working with? Perhaps this will also explain where you get the ["Process PID: xxxx"](https://stackoverflow.com/questions/65478400/boost-unit-test-start-but-not-execute/65499958?noredirect=1#comment115909738_65499958) messages [from] ¯\_(ツ)_/¯ – sehe Jan 04 '21 at 13:41

1 Answers1

0

It's unclear how you arrive at the conclusion the test is not running. It would seem it explicitly states that it is running the test (and passing).

However, the time consumed doesn't match your expectation, which leads to the guess that you may be running the wrong target (an old build e.g. one of a build configuration that is not up-to-date).

Command Line

Given the test suite name, the command line argument should be like:

./sotest --log_level=message --run_test=_obj_interface_/init_string

Which for me prints:

Running 1 test case...
init_string

*** No errors detected

You can use some wildcards if you want:

./sotest -l all -t "*/init_string"
Running 1 test case...
Entering test module "SimpleTest"
/home/sehe/Projects/stackoverflow/test.cpp(20): Entering test suite "_obj_interface_"
/home/sehe/Projects/stackoverflow/test.cpp(22): Entering test case "init_string"
init_string
/home/sehe/Projects/stackoverflow/test.cpp(45): info: check conf.isComplete() == true has passed
/home/sehe/Projects/stackoverflow/test.cpp(53): info: check 'no exceptions thrown by objIf.init(conf)' has passed
/home/sehe/Projects/stackoverflow/test.cpp(22): Leaving test case "init_string"; testing time: 3000212us
/home/sehe/Projects/stackoverflow/test.cpp(20): Leaving test suite "_obj_interface_"; testing time: 3000270us
Leaving test module "SimpleTest"; testing time: 3000294us

*** No errors detected

Use --list_content to ... list the contents:

 sehe  ~  Projects  stackoverflow  ./sotest --list_content
_obj_interface_*
    init_string*

Warning About Naming

Names starting with underscores (or containing double __ underscores) are reserved. Using them makes your program not well-formed and you may run into issues. See What are the rules about using an underscore in a C++ identifier?

So you should probably change the name of your test suite.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • The code I used to repro with: [just simple inline mocks](http://coliru.stacked-crooked.com/a/fda069483e30a6de) – sehe Dec 29 '20 at 23:14
  • I arrive at the conclusion that it does not perform for the execution time and because I would have expected at least the printing of the message "init_string". Furthermore, putting an assert statement that is always false does not give me any errors. However, by executing the three proposed commands I always get the following output "Process PID: xxxx". Thanks for the reply. – coman Jan 04 '21 at 08:35
  • That's pretty unclear. Where do you get "Process PID: xxxx"? That's not in the question. I hope my live demo shows how you should expect it to work, and what steps make it work. I'm suspecting there's a more fundamental confusion going on with tools that you didn't mention. I'll comment at your question for more info – sehe Jan 04 '21 at 13:38