Catch2 alternative Section behaviour

Viewed 292

I am using Catch2 and I am trying to build a test case which does a complicate setup before the sections, represented in the listing by the initialization of a MyObject instance.

I like the idea of sections, since they keep the tests separated, but I would like to avoid the initialization of MyObject before every Section, is it possible?

TEST_CASE("Example"){

  MyObject obj{param1, param2}; /* This takes time! */

 SECTION("Check 1"){
    REQUIRE(obj.foo() == 42);
  }  

  SECTION("Check 2"){
     REQUIRE(obj.bar() == 58);
  }

}
0 Answers
Related