What does this skill do?

The Testing in Go Skill provides idiomatic testing patterns in Go for writing reliable and maintainable tests. It covers everything from table-based tests and subtests to benchmarks, fuzzing, and code coverage analysis, following the TDD (Test-Driven Development) methodology with the RED-GREEN-Refactor workflow.

Table-Driven Tests
Create table-based tests to achieve comprehensive coverage with as little code as possible.
Performance Benchmarks
Measure the performance of critical functions and detect bottlenecks using ns/op and allocs/op metrics.
Fuzzing (Go 1.18+)
Test the handling of unexpected inputs by generating random data that can cause panics or errors.
Code Coverage
Generate coverage profiles and view what percentage of the code is covered by the tests.

Usage examples

🧪 Basic TDD
Create the Add function using TDD: first write the test that fails, then the minimal implementation.
📊 Benchmark
Write a benchmark for the `Process` function that measures ns/op and allocs/op with 1,000 elements.
🎲 Fuzzing
Generate a fuzz test for ParseJSON that verifies that Marshal never fails after a successful Unmarshal.
🌐 HTTP Handler
Create a test using httptest for HealthHandler to verify that it returns a 200 status code.

Features

Strict TDD Methodology Follow the RED-GREEN-Refactor flow: define the signature, write the test that fails, implement the bare minimum, and refactor.
Table-Based Tests A standard Go pattern for handling multiple cases with minimal code duplication.
Benchmarks with Metrics Measure ns/op, B/op, and allocs/op using ResetTimer to exclude setup time.
Native fuzzing (Go 1.18+) Generate random inputs based on the initial corpus and automatically save failure cases in testdata/fuzz/.
Visual coverage Generate coverage profiles using `go test -coverprofile` and view them in the browser using `go tool cover`.

Frequently asked questions

For native fuzzing, you need Go 1.18 or later. The other patterns (table-driven tests, benchmarks, httptest) work in earlier versions.
Yes. The skill follows the RED-GREEN-Refactor cycle: first, it defines the signature with `panic("not implemented")`, writes a test that fails, implements the bare minimum to make it pass, and then refactors the code.
Run `go test -bench=BenchmarkProcess -benchmem` to view performance metrics and memory allocations.
Yes. All the patterns (table-driven tests, httptest, fuzzing) are idiomatic templates that you can adapt to your functions and packages.
Testing in Go — Language Testing and TDD with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.