Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different preconditions but same set of checks #2251

Open
zrno opened this issue Jun 17, 2021 · 0 comments
Open

Different preconditions but same set of checks #2251

zrno opened this issue Jun 17, 2021 · 0 comments
Labels

Comments

@zrno
Copy link

zrno commented Jun 17, 2021

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.
#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

@horenmar horenmar added the Query label Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants