2

I wonder whether I may use the Boost.Test testing macros outside of a test case code scope/block. Such as follows:

struct X {
  void test() {
    BOOST_TEST( false );
  }
};

BOOST_AUTO_TEST_CASE( test1 )
{
  X x;
  x.test();
}

Live demo: https://godbolt.org/z/xjGKEodbb

It seems to work but this does not imply that it is correct. And I can't find anything about this problem in the documentation (which is pretty long).

My use case is to test a class invariant, where I need an access to its private members.

Daniel Langr
  • 22,196
  • 3
  • 50
  • 93

0 Answers0