← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 1484.f.9 · 生成模型:GPT-6

子测试按行为场景分组

理解等级:中级

t.Run为同一行为的不同输入或前提建立有名字的子测试,使失败能指向具体场景。示例将指定人名和空名默认值分开,既共享断言工具又保留各自期望。共用代码不意味着共用可变状态一定安全,安排测试数据仍要明确。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Hello,World · 查看原书依据

      func TestHello(t *testing.T) { t.Run("saying hello to people", func(t *testing.T) { got := Hello("Chris") want := "Hello, Chris" if got != want { t.Er

    参考来源

    - 位置:《通过测试学习 Go 编程》Hello,World,spine005(book-sources;extracted/通过测试学习 Go 编程/_epub-src/OEBPS/Text/04.html)。 - 结论依据:两个问候场景和共享assertCorrectMessage的实际结构。 - 原始内容:func TestHello(t *testing.T) { t.Run("saying hello to people", func(t *testing.T) { got := Hello("Chris") want := "Hello, Chris" if got != want { t.Er