cucumber / cucumber/cucumber-cpp
How to get the current scenario name in HOOK_AFTER_SCENARIO or HOOK_BEFORE_SCENARIO?
- Dominant language
- C++
- Stars
- 330
- Forks
- 140
- PR merge metrics
- No merged PRs in 30d
Description
### 🤔 What's the problem you've observed?
current_test_info() is null in HOOK_AFTER_SCENARIO
Hi,
I'm using cucumber-cpp and noticed that ::testing::UnitTest::GetInstance()->current_test_info() returns nullptr inside HOOK_AFTER_SCENARIO().
Example:
HOOK_AFTER_SCENARIO()
{
const auto* test_info =
::testing::UnitTest::GetInstance()->current_test_info();
if (test_info) {
std::cout << test_info->name() << std::endl;
} else {
std::cout << "test_info is null" << std::endl;
}
}
The hook is executed correctly, but test_info is always nullptr.
My goal is to obtain the current scenario/test name during HOOK_AFTER_SCENARIO() for reporting purposes.
Is this expected behavior?
If so, could you please advise what the recommended way is to retrieve the current scenario name from within HOOK_AFTER_SCENARIO()?
Thanks!
### ✨ Do you have a proposal for making it better?
_No response_
### 📚 Any additional context?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.