doctest
doctest copied to clipboard
Add a BDD style 'EXPECT' clause as in GIVEN/EXPECT/WHEN to be aligned with mock frameworks constraints
Most, if not all, mock frameworks out there require to declare the expected callbacks BEFORE executing the stimulus on the SUT. This defers from the regular pattern of GIVEN/WHEN/THEN where the expectations are checked AFTER the stimulus.
So to be more readable, one would prefer to complete the pattern with something like GIVEN[/EXPECT]/WHEN[/THEN]. This can be achieved by adding a new define like this:
#define EXPECT(name) DOCTEST_SUBCASE(" Expect: " name)
#define AND_EXPECT(name) DOCTEST_SUBCASE(" And: " name)
Example of usage with gmock:
SCENARIO("example of mock usage") {
GIVEN("an initial state") {
NaggyMock<MyMock> myMock;
MyClass sut(myMock);
EXPECT("my mock callback to be called once") {
EXPECT_CALL(myMock, myCallback());
WHEN("the SUT is stimulated") {
sut.callMeMaybe();
}
}
}
}
This and the other BDD-related issue will go into the next release. Thanks for reporting!