-
Notifications
You must be signed in to change notification settings - Fork 86
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
Best way to use with Catch2 - BDD style #148
Comments
I have also been struggling with this issue. |
One thing you can do is to check if the expectation is satisfied.
I'm not sure if that is any better, though. Another way is to use |
I realize there are a few too many |
If you use the catch2 adapter you get a reasonable error message. There's also an improved adapter on the
However, catch2 is behaving in a somewhat confusing way here. If you have a bug that |
Thank you for your effort! Now that I revisit this problem, maybe this could be a cleanier approach BarMocksCAPI bar_mock;
BazMocksCAPI baz_mock;
SCENARIO("foo") {
GIVEN("foo in reset state") {
WHEN("foo is initialized") {
std::unique_ptr<trompeloeil::expectation> expected_mock_call;
THEN("bar should be initialized") {
expected_mock_call = NAMED_REQUIRE_CALL(bar_mock, bar_init());
}
THEN("baz should be initialized") {
expected_mock_call = NAMED_REQUIRE_CALL(baz_mock, baz_init());
}
foo_init();
THEN("foo should be initialized") {
CHECK(foo_initialized() == 1)
}
expected_mock_call.reset()
}
}
} And in case in each THEN block multiple mocking expectations need to be set, maybe a vector of unique_ptr could be used. |
When writing BDD tests with Catch2, we have something like this:
What I would like to do is to give some mock call expectation a meaningful name, i.e. put it into a THEN block.
I know that I can achieve what I want by using NAMED_*
But I'm wondering whether there could be a tidier way to express this.
The text was updated successfully, but these errors were encountered: