Skip to content

How to get the current scenario name in HOOK_AFTER_SCENARIO or HOOK_BEFORE_SCENARIO? #317

@IronsDu

Description

@IronsDu

🤔 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions