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

未关闭
#317 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
cpp
领域
testing

调研方向

从 HOOK_AFTER_SCENARIO() 和 current_test_info() 调用入手,然后检查 cucumber-cpp 如何将 scenario hook 映射到 GoogleTest 生命周期。完成标准是确定 null 是否为预期值,并记录或确认获取 scenario 名称用于报告的受支持方式。

由索引模型根据 Issue 内容生成。

描述

🤔 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

主要语言
C++
星标
330
派生
142
平均合并
2 天 8 小时
30 天内合并 PR
2

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cucumber/cucumber-cpp 的其他 Issue

查看 cucumber/cucumber-cpp 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。