Chuyển đến nội dung
Skillpedia
Kiểm thử9.1k · #12305

reporting

Skill này làm gì

Skill này giải thích cách kiểm soát giao diện kết quả kiểm thử Ginkgo và cách lưu chúng thành báo cáo mà máy có thể đọc. Nó dành cho lập trình viên muốn đầu ra kiểm thử rõ ràng hoặc báo cáo cho các công cụ khác.

Khi nào nên dùng

  • ✓Khi bạn muốn xem nhiều hoặc ít chi tiết hơn trong kết quả kiểm thử hiển thị trên màn hình.
  • ✓Khi bạn cần một file báo cáo JSON hoặc JUnit từ các bài kiểm thử Ginkgo.
  • ✓Khi bạn muốn kiểm tra độ phủ code hoặc hiệu năng của các bài kiểm thử Go.

Liên kết skill

https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/reporting/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/reporting/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể làm các bài kiểm thử Go của tôi lưu một báo cáo JUnit để hệ thống CI của chúng tôi đọc được không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill chỉ ra các tùy chọn lệnh để in đầu ra chi tiết, ghi file báo cáo, và đo độ phủ hoặc tốc độ.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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-report is native and richest — an array of types.Report, each with SpecReports[] of types.SpecReport (godoc); build tooling against the types package.
  • --junit-report=x.xml, --teamcity-report=x, --gojson-report=x.go.json exist for external CI but lose Ginkgo metadata — use them to feed a system, not to diagnose. (JUnit maps a Label("owner:XYZ") to the Owner attribute.)
  • --output-dir=DIR collects all files in one place; under -r all suites merge into one report file. --keep-separate-reports writes one PACKAGE_report.json per package instead.
  • Every machine-readable report embeds the full -vv timeline regardless of console verbosity. Run the suite quiet and mine the file — you don't need -vv on 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 (unlike AfterEach), after all AfterEaches. 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. ReportAfterSuite receives the Report aggregated 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 (like GinkgoWriter).
  • 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

Câu hỏi thường gặp

Báo cáo JUnit là gì?

Đó là một định dạng file tiêu chuẩn mà nhiều hệ thống build và kiểm thử có thể đọc để hiển thị kết quả.

Tôi có thể xem từng bài kiểm thử khi nó đang chạy không?

Có. Các tùy chọn verbose hiển thị dòng thời gian cho mỗi bài kiểm thử, dù khi chạy song song, mỗi dòng thời gian chỉ hiện sau khi bài đó kết thúc.

Skill này có thay đổi các bài kiểm thử của tôi không?

Nó chủ yếu nói về tùy chọn lệnh và code báo cáo, nên các bài kiểm thử của bạn vẫn giữ nguyên trừ khi bạn thêm bước báo cáo.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
9.1k
Vị trí xếp hạng
#12305
Giấy phép
MIT
Cập nhật
9/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự