mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-27 13:13:30 +01:00
Merge branch 'master' of https://github.com/jbrwilkinson/Catch
# By James Wilkinson # Via James Wilkinson * 'master' of https://github.com/jbrwilkinson/Catch: Added SCENARIO_METHOD for BDD testing with fixtures.
This commit is contained in:
commit
7bc0b44597
@ -112,8 +112,10 @@
|
||||
// "BDD-style" convenience wrappers
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
|
||||
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||
#else
|
||||
#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
|
||||
#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
|
||||
#endif
|
||||
#define CATCH_GIVEN( desc ) CATCH_SECTION( "Given: " desc, "" )
|
||||
#define CATCH_WHEN( desc ) CATCH_SECTION( " When: " desc, "" )
|
||||
@ -179,8 +181,10 @@
|
||||
// "BDD-style" convenience wrappers
|
||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
||||
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
|
||||
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||
#else
|
||||
#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
|
||||
#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
|
||||
#endif
|
||||
#define GIVEN( desc ) SECTION( " Given: " desc, "" )
|
||||
#define WHEN( desc ) SECTION( " When: " desc, "" )
|
||||
|
@ -66,3 +66,38 @@ SCENARIO( "This is a really long scenario name to see how the list command dea
|
||||
THEN( "The, deliberately very long and overly verbose (you see what I did there?) section names must wrap, along with an indent" )
|
||||
SUCCEED("boo!");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// a trivial fixture example to support SCENARIO_METHOD tests
|
||||
struct Fixture
|
||||
{
|
||||
Fixture()
|
||||
: d_counter(0)
|
||||
{
|
||||
}
|
||||
|
||||
int counter()
|
||||
{
|
||||
return d_counter++;
|
||||
}
|
||||
|
||||
int d_counter;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
SCENARIO_METHOD(Fixture,
|
||||
"BDD tests requiring Fixtures to provide commonly-accessed data or methods",
|
||||
"[bdd][fixtures]") {
|
||||
const int before(counter());
|
||||
GIVEN("No operations precede me") {
|
||||
REQUIRE(before == 0);
|
||||
WHEN("We get the count") {
|
||||
const int after(counter());
|
||||
THEN("Subsequently values are higher") {
|
||||
REQUIRE(after > before);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user