Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计通过

go-testing去测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

12,929

周安装

518

GitHub Stars

81

下载量

4,185
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:go-testing(去测试)
来源仓库:https://github.com/cxuu/golang-skills
仓库路径:skills/go-testing
安装命令:
npx skills add https://github.com/cxuu/golang-skills --skill go-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/cxuu/golang-skills --skill go-testing

简介

Go 测试参考提供可诊断失败的测试编写准则与常用模式。

  • 适用于单元测试、子测试与表格驱动用例组织。
  • 强制包含函数名、输入、got/want 信息,提升排查效率。
  • 辅助函数必须声明 t.Helper(),确保失败定位准确。
  • go-testing 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Go Testing

Quick Reference

PatternUse When
t.ErrorDefault — report failure, keep running
t.FatalSetup failed or continuing is meaningless
cmp.DiffComparing structs, slices, maps, protos
Table-drivenMany cases share identical logic
SubtestsNeed filtering, parallel execution, or naming
t.Helper()Any test helper function (call as first statement)
t.Cleanup()Teardown in helpers instead of defer

Useful Test Failures

Normative: Test failures must be diagnosable without reading the test source.

Every failure message must include: function name, inputs, actual (got), and expected (want). Use the format YourFunc(%v) = %v, want %v.

// Good:
t.Errorf("Add(2, 3) = %d, want %d", got, 5)

// Bad: Missing function name and inputs
t.Errorf("got %d, want %d", got, 5)

Always print got before want: got %v, want %v — never reversed.


No Assertion Libraries

Normative: Do not use assertion libraries. Use cmp.Diff for complex comparisons.
if diff := cmp.Diff(want, got); diff != "" {
    t.Errorf("GetPost() mismatch (-want +got):\n%s", diff)
}

For protocol buffers, add protocmp.Transform() as a cmp option. Always include the direction key (-want +got) in diff messages. Avoid comparing JSON/serialized output — compare semantically instead.

Read references/TEST-HELPERS.md when writing custom comparison helpers or domain-specific test utilities.

t.Error vs t.Fatal

Normative: Use t.Error by default to report all failures in one run. Use t.Fatal only when continuing is impossible.

Choose t.Fatal when:

  • Setup fails (DB connection, file load)
  • The next assertion depends on the previous one succeeding (e.g., decode after encode)

Never call t.Fatal/t.FailNow from a goroutine other than the test goroutine — use t.Error instead.

Read references/TEST-HELPERS.md when writing helpers that need to choose between t.Error and t.Fatal, or for detailed examples of both.

Table-Driven Tests

See assets/table-test-template.go when scaffolding a new table-driven test and need the canonical struct, loop, and subtest layout.
Advisory: Use table-driven tests when many cases share identical logic.

Use table tests when: all cases run the same code path with no conditional setup, mocking, or assertions. A single shouldErr bool is acceptable.

Don't use table tests when: cases need complex setup, conditional mocking, or multiple branches — write separate test functions instead.

Key rules:

  • Use field names when cases span many lines or have same-type adjacent fields
  • Include inputs in failure messages — never identify rows by index
Read references/TABLE-DRIVEN-TESTS.md when writing table-driven tests, subtests, or parallel tests.
Validation: After generating or modifying tests, run go test -run TestXxx -v to verify the tests compile and pass. Fix any compilation errors before proceeding.

Test Helpers

Normative: Test helpers must call t.Helper() first and use t.Cleanup() for teardown.
func setupTestDB(t *testing.T) *sql.DB {
    t.Helper()
    db, err := sql.Open("sqlite3", ":memory:")
    if err != nil {
        t.Fatalf("Could not open database: %v", err)
    }
    t.Cleanup(func() { db.Close() })
    return db
}
Read references/TEST-HELPERS.md when writing test helpers, cleanup functions, or custom comparison utilities.

Test Error Semantics

Advisory: Test error semantics, not error message strings.
// Bad: Brittle string comparison
if err.Error() != "invalid input" { ... }

// Good: Semantic check
if !errors.Is(err, ErrInvalidInput) { ... }

For simple presence checks when specific semantics don't matter:

if gotErr := err != nil; gotErr != tt.wantErr {
    t.Errorf("f(%v) error = %v, want error presence = %t", tt.input, err, tt.wantErr)
}

Test Organization

Read references/TEST-ORGANIZATION.md when working with test doubles, choosing test package placement, or scoping test setup.
Read references/VALIDATION-APIS.md when designing reusable test validation functions.

Integration Testing

Read references/INTEGRATION.md when writing TestMain, acceptance tests, or tests that need real HTTP/RPC transports.

Available Scripts

  • scripts/gen-table-test.sh — Generates a table-driven test scaffold
bash scripts/gen-table-test.sh ParseConfig config > config/parse_config_test.go
bash scripts/gen-table-test.sh --parallel ParseConfig config      # with t.Parallel()
bash scripts/gen-table-test.sh --output config/parse_config_test.go ParseConfig config

Related Skills

  • Error testing: See go-error-handling when testing error semantics with errors.Is/errors.As or sentinel errors
  • Interface mocking: See go-interfaces when creating test doubles by implementing interfaces at the consumer side
  • Naming test functions: See go-naming when naming test functions, subtests, or test helper utilities
  • Linter integration: See go-linting when running linters alongside tests in CI or pre-commit hooks

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

39.38%
按下载量换算1,648

Claude

28.58%
按下载量换算1,196

Cursor

19.65%
按下载量换算822

Gemini CLI

8.49%
按下载量换算355

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills