3

I have a unit test file using Boost Test, like so:

#include <boost/test/unit_test.hpp>
#include <cppx/auto/Cloner_.hpp>
#include <utility>

namespace {
    struct S
    {
        static auto count() -> int& { static int c; return c; }

        S(){ ++count(); }
        S( const S& ) { ++count(); }
        S( S&& ) { ++count(); }
        ~S() { --count(); }
    };
}

BOOST_AUTO_TEST_SUITE( Cloner_ )

    BOOST_AUTO_TEST_CASE( default_construction )
    {
        cppx::Cloner_<int> cloner1;
        BOOST_TEST( cloner1.p() == nullptr );
    }

    BOOST_AUTO_TEST_CASE( auto_cleanup )
    {
        BOOST_REQUIRE( S::count() == 0 );

        {
            cppx::Cloner_<S> cloner1( new S );
            BOOST_TEST( S::count() == 1 );
            cppx::Cloner_<S> cloner2 = cloner1.clone();
            BOOST_TEST( S::count() == 2 );
        }
        BOOST_TEST( S::count() == 0 );
    }

BOOST_AUTO_TEST_SUITE_END()

My purpose with the test suite name Cloner_ is to collect all the test cases for the Cloner_ class, under a node in the Boost test cases hierarchy.

When I choose to run all tests in Visual Studio it detects this hierarchy:

[22.09.2018 06:18:37 Informational] ------ Run test started ------
[22.09.2018 06:18:39 Informational] Found test: Cloner_/auto_cleanup
[22.09.2018 06:18:39 Informational] Found test: Cloner_/default_construction
[22.09.2018 06:18:39 Informational] Executing:   -> [Cloner_/auto_cleanup]
[22.09.2018 06:18:40 Informational] Executing:   -> [Cloner_/default_construction]
[22.09.2018 06:18:40 Informational] ========== Run test finished: 2 run (0:00:03,1048741) ==========

However, it doesn't display the hierarchy, except that it uses the main Boost test module name cppx_tests (defined in a separate file) as root:

enter image description here

(Visual Studio's Test Explorer's presentation of the test cases is up to the right in the above screenshot.)

I'd like to avoid old-fashioned C style name prefixes since Boost Test does provide a means of defining a hierarchy, and since Test Explorer reports paths in that hierarchy when it searches for tests to execute, so that it apparently knows about it.

So, how can I make VS Test Explorer display the test case hierarchy for tests using Boost Test, so that I can readily identify e.g. default_construction testing of class X versus class Y or class Z, or is that not possible?

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331
  • I found that "Group by Traits" displays each test suite's path as a root for the test cases directly in the suite. But it doesn't display the hierarchy as such, and it adds an extraneous (to me) grouping "Status [Enabled]". I guess if there is no hierarchy display this will have to do, but it sucks. – Cheers and hth. - Alf Sep 22 '18 at 04:42

0 Answers0