reporting
它能做什么
这项技能讲解如何控制 Ginkgo 测试结果的显示方式,以及如何把结果保存为机器可读的报告。适合希望测试输出清晰,或需要为其他工具提供报告的开发者。
适用场景
- ✓当你想在屏幕上看到更多或更少的测试结果细节时。
- ✓当你需要 Ginkgo 测试生成 JSON 或 JUnit 报告文件时。
- ✓当你想检查 Go 测试的代码覆盖率或性能时。
技能链接
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/reporting/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“你能让我的 Go 测试保存一份 JUnit 报告,供我们的持续集成系统读取吗?”
每周 5 个新技能,1 分钟读完。
工作原理
它展示了哪些命令选项可以输出详细信息、写入报告文件,以及测量覆盖率或速度。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Reporting and profiling
How to produce reports and feed data into them. To read a failing report as an agent (the jq failure-diagnosis workflow), see ginkgo:debugging-failures. Docs: https://onsi.github.io/ginkgo/#generating-machine-readable-reports and https://onsi.github.io/ginkgo/#attaching-data-to-reports.
Console output
| Flag | Effect |
|---|---|
--succinct |
Minimal (default when running multiple suites). |
| (none) | Normal — detail only for failed specs (default, single suite). |
-v |
Full timeline for every spec; streams live in series. |
-vv |
-v plus node > Enter/< Exit events and every failure (not just the primary). |
--trace |
Full stack trace on every failure, not just panics. |
--no-color / GINKGO_NO_COLOR=TRUE |
Disable color. |
--github-output |
Format console output for GitHub Actions. |
In parallel (-p), -v/-vv timelines can't stream — the streams would interleave, so Ginkgo emits each spec's full timeline after that spec completes. → CI flags in ginkgo:ci.
Machine-readable reports
ginkgo -r --json-report=report.json --output-dir=./.reports
--json-reportis native and richest — an array oftypes.Report, each withSpecReports[]oftypes.SpecReport(godoc); build tooling against thetypespackage.--junit-report=x.xml,--teamcity-report=x,--gojson-report=x.go.jsonexist for external CI but lose Ginkgo metadata — use them to feed a system, not to diagnose. (JUnit maps aLabel("owner:XYZ")to theOwnerattribute.)--output-dir=DIRcollects all files in one place; under-rall suites merge into one report file.--keep-separate-reportswrites onePACKAGE_report.jsonper package instead.- Every machine-readable report embeds the full
-vvtimeline regardless of console verbosity. Run the suite quiet and mine the file — you don't need-vvon the console to get rich detail in the report.
Programmatic reporting nodes
CurrentSpecReport() works in any run-phase closure — use it for in-spec conditional diagnostics:
AfterEach(func() {
if CurrentSpecReport().Failed() {
GinkgoWriter.Println(libraryClient.DebugLogs()) // expensive diagnostics, only on failure
}
})
For custom report files, don't roll your own in AfterEach — use reporting nodes:
ReportAfterEach(func(r SpecReport){...})/ReportBeforeEach— run for every spec including skipped/pending (unlikeAfterEach), after allAfterEaches. A failure here fails the spec. In parallel they run on each process concurrently — never write a shared file from them (you'll get interleaved garbage).ReportBeforeSuite/ReportAfterSuite("name", func(r Report){...})— top-level, and run only on process #1.ReportAfterSuitereceives theReportaggregated across all parallel processes — this is the safe place for custom suite-level report files:
ReportAfterSuite("custom report", func(report Report) {
f, _ := os.Create("report.custom")
for _, sr := range report.SpecReports {
fmt.Fprintf(f, "%s | %s\n", sr.FullText(), sr.State)
}
f.Close()
})
Reporting nodes can be made interruptible by also accepting SpecContext → ginkgo:timeouts-and-async.
Attaching data to a spec: AddReportEntry
It("is reported", func() {
AddReportEntry("Publish stats", stats, ReportEntryVisibilityFailureOrVerbose)
})
AddReportEntry(name, value, ...args) attaches arbitrary data to the current spec; it lands in SpecReport.ReportEntries, in all machine-readable reports, and (per visibility) on the console. Visibility enum:
ReportEntryVisibilityAlways(default) — always printed.ReportEntryVisibilityFailureOrVerbose— only on failure or-v(likeGinkgoWriter).ReportEntryVisibilityNever— never on console, but still in the JSON report.
For failure-only diagnostics, call AddReportEntry from a DeferOnFailure callback (→ ginkgo:writing-specs).
value is JSON-round-tripped into the report (retrieve via entry.GetRawValue() / json.Unmarshal(entry.Value.AsJSON, ...)). A fmt.Stringer/types.ColorableStringer controls console rendering; pass a pointer to capture later mutations. AddReportEntry decorators (Offset, CodeLocation, ReportEntryVisibility) → ginkgo:decorators.
Recap (owned by ginkgo:writing-specs): GinkgoWriter buffers log output a
常见问题
什么是 JUnit 报告?
它是一种标准文件格式,许多构建和测试系统都能读取它来显示测试结果。
我能看到每个测试的运行过程吗?
能。详细输出选项会显示每个测试的时间线,不过并行运行时,每条时间线会在该测试结束后才显示。
这项技能会修改我的测试吗?
不会。它主要涉及命令选项和报告代码,除非你添加报告步骤,否则测试保持不变。
详情
作者的原始描述
Generate, consume, and enrich Ginkgo reports — console verbosity (-v/-vv/--trace/--no-color/--succinct), machine-readable reports (--json-report/--junit-report with --output-dir/--keep-separate-reports), programmatic reporting nodes (ReportAfterEach, ReportAfterSuite, CurrentSpecReport), AddReportEntry with ReportEntryVisibility, and profiling (--cover/--race/--cpuprofile/--memprofile). Use when you need a report file, custom suite-level reporting, attaching data to a spec, controlling console output, or profiling a suite.
repo: onsi/ginkgo
热度
- GitHub 星标
- 9.1k
- 排名
- #12305
- 许可证
- MIT
- 更新时间
- 2026/10/9
评论
- …
同一仓库的更多技能
ci
9.1k帮你的智能体为持续集成设置 Ginkgo 测试,使用推荐的参数,能捕捉遗留的 Focus 或 Pending 标记以及不稳定的测试。
debugging-failures
9.1k帮你的智能体通过阅读摘要行,并从 JSON 报告中提取确切的失败测试和消息,找出 Ginkgo 测试失败的原因。
decorators
9.1k帮你的智能体正确使用 Ginkgo 测试装饰器,例如 Serial、Ordered、Label、Focus 和超时设置,并解释每一个的作用。
filtering
9.1k帮你的智能体只运行部分 Ginkgo 测试,按正确的优先顺序使用 pending、skip、focus、标签、版本约束和文件过滤器。