Catch2
Catch2 copied to clipboard
Different preconditions but same set of checks
Description I would like to write BDD tests where the same set of checks is executed for different preconditions to reduce code duplication. Another older issue had the same question and was closed but I don't think the issue is solved in an elegant way. https://github.com/catchorg/Catch2/issues/603
TEST_CASE("Test foo1")
{
Foo foo;
foo.Method1();
REQUIRE(foo.hasSomething());
REQUIRE(....);
}
TEST_CASE("Test foo2")
{
Foo foo;
foo.Method2();
REQUIRE(foo.hasSomething());
REQUIRE(....);
}
Additional context I would like to write unit tests that look like this:
TEST_CASE("Test foo")
{
Foo foo;
SCENARIO_CONDITION("Precondition1")
{
foo.Method1();
}
OR_SCENARIO_CONDITION("Precondition2")
{
foo.Method2();
}
REQUIRE(foo.hasSomething());
REQUIRE(....);
}
I have a feeling this could be easily achieved with the current state of Catch2 and the existing generators but I am unfamiliar with the code to propose a solution myself