Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

writing-go-tests编写 go 测试

Agent Skill

用于辅助文档、README、Markdown、说明文和内容稿件的整理与改写。它适合让 Agent 提炼结构、补齐章节、统一术语、检查链接或把零散材料整理成可读文档。使用时应保留项目已有事实、命令和路径,不要把未确认的信息写成确定结论;涉及对外文案时,还需要控制语气,避免过度营销或夸大能力。

总安装

1,327

周安装

57

GitHub Stars

125

下载量

465
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/sammcj/agentic-coding --skill writing-go-tests

简介

用于为 Go 语言项目编写单元测试。

  • 适合补充现有代码的测试覆盖范围。writing-go-tests 属于前端设计类 Skill,可作为该场景下的辅助能力补充。
  • 可生成符合 Go 测试规范的用例模板。
  • 需了解项目依赖和函数签名后再生成测试。
  • 应避免直接运行未经验证的测试代码。适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Go Testing Best Practices

This skill provides actionable testing guidelines. For detailed implementation patterns, code examples, rationale, and production system references, consult go-testing-best-practices.md.

When Working with Go Tests

Always apply these current best practices:

1. Test Organisation

  • Place test files alongside source code using *_test.go naming
  • Use internal tests (same package) for unit testing unexported functions
  • Use external tests (package foo_test) for integration testing and examples
  • Split test files by functionality when they exceed 500-800 lines (e.g., handler_auth_test.go, handler_validation_test.go)

2. Table-Driven Testing

  • Prefer map-based tables over slice-based for automatic unique test names
  • Use descriptive test case names that appear in failure output
  • See detailed guide for complete pattern and examples

3. Concurrent Testing

  • Use testing/synctest for deterministic concurrent testing (Go 1.24+)
  • This eliminates flaky time-based tests and runs in microseconds instead of seconds
  • For traditional parallel tests, always call t.Parallel() first in test functions

4. Assertions and Comparisons

  • Use cmp.Diff() from google/go-cmp for complex comparisons
  • Standard library is sufficient for simple tests
  • Testify is the dominant third-party framework when richer assertions are needed

5. Mocking and Test Doubles

  • Favour integration testing with real dependencies over heavy mocking
  • Use Testcontainers for database/service integration tests
  • When mocking is necessary, prefer simple function-based test doubles over code generation
  • Use interface-based design ("accept interfaces, return structs")

6. Coverage Targets

  • Aim for 70-80% coverage as a practical target
  • Focus on meaningful tests over percentage metrics
  • Use go test -cover and go tool cover -html for analysis

7. Test Fixtures

  • Use testdata directory for test fixtures (automatically ignored by Go toolchain)
  • Implement golden file testing for validating complex output
  • Use functional builder patterns for complex test data

8. Helpers and Cleanup

  • Always mark helper functions with t.Helper() for accurate error reporting
  • Use t.Cleanup() for resource cleanup (superior to defer in tests)

9. Benchmarking (Go 1.24+)

  • Use B.Loop() method as the preferred pattern (prevents compiler optimisations)
  • Combine with benchstat for statistical analysis
  • Use -benchmem for memory profiling

10. Naming Conventions

  • Test functions: Test*, Benchmark*, Fuzz*, Example* (capital letter after prefix)
  • Use got and want for actual vs expected values
  • Use descriptive test case names in table-driven tests

Integration vs Unit Testing

  • Separate tests by environment variable (preferred over build tags)
  • See detailed guide for implementation pattern

Additional Reference Material

Load go-testing-best-practices.md when you need:

  • Complete code examples for table-driven tests, mocking patterns, golden files, helpers, or benchmarks
  • Detailed explanation of testing/synctest concurrent testing patterns
  • Rationale behind why specific patterns are preferred over alternatives
  • Production system examples and statistics (Kubernetes, Docker, Uber, Netflix, ByteDance)
  • Context on testing framework choices (Testify, GoMock, Testcontainers)
  • Comprehensive coverage strategies and tooling details
  • Integration testing patterns with containerisation

The detailed guide contains full context, examples with explanations, and production-proven patterns. This SKILL.md provides the actionable rules to apply.

Key Principle

Focus on meaningful tests that validate behaviour rather than implementation. Pragmatic excellence over theoretical perfection.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

32.76%
按下载量换算152

Claude

28.7%
按下载量换算133

Cursor

19.62%
按下载量换算91

Gemini CLI

10.57%
按下载量换算49

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

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

来源信息

继续浏览同类 Skills