catchorg / catchorg/Catch2

Reusable BDD sections

Open
#2,665 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
21.5k
Forks
3.5k
Avg merge
3d 16h
Merged PRs (30d)
2

Description

One of pros the BDD autotesting is to facilitate reusability.
For example, you might have many tests needing the `GIVEN("My algo is in step A")` and you don't necessary want to push all those tests in the same scenario.
The idea would be to write the corresponding code for "My algo is in step A" only once and being able to reuse it anywhere.

The usage might looks like something like that:

```
REGISTER_GIVEN( "A vector with some items" ) {
...source code ...
}

GIVEN( "A vector with some items" ) {
// no code here -> the registered code should expand here

WHEN( "the size is reduced" ) {
v.resize( 0 );

THEN( "the size changes but not capacity" ) {
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
}
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing BDD autotesting implementation for how GIVEN sections are defined and expanded. Determine how a named GIVEN could be registered once and reused in other scenarios, then verify that the example usage works without duplicating its setup code.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.