golang-gin-testing

Write unit, integration, e2e, and load tests for Go Gin REST APIs.

1|Updated Jul 4, 2026
One-click install
npx skills add https://github.com/trungenglish/SHOPWISE --skill golang-gin-testing-trungenglish
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-gin-testing
Source: https://github.com/trungenglish/SHOPWISE/tree/main/.agents/skills/golang-gin-testing
Command: npx skills add https://github.com/trungenglish/SHOPWISE --skill golang-gin-testing-trungenglish

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Testing Go Gin APIs requires coordinating many patterns — httptest recorders, mocked repositories, table-driven subtests, testcontainers for real databases, and CI pipelines — and developers often end up with shallow handler tests that miss error paths, race conditions, and SQL correctness issues. ## Core Features & Use Cases - Unit Testing Patterns: Handler tests with httptest and mock services, service tests with mocked repositories, table-driven validation tests, fixtures, middleware isolation tests, benchmarks, fuzz tests, and golden file snapshots. - Integration & E2E Testing: TestMain lifecycle with testcontainers PostgreSQL, truncate/rollback cleanup, migration up/down tests, fixture loading, and full register→login→CRUD flows. - Load Testing & CI: Go benchmarks, Vegeta and k6 scripts with latency thresholds, benchstat regression detection, and a three-job GitHub Actions pipeline with an 80% coverage gate. - Use Case: You just built a UserHandler with JWT-protected routes. Use this Skill to generate table-driven validation tests, service tests asserting typed AppError codes with errors.As, and an integration suite that verifies duplicate-email constraints against a real Postgres container. ## Quick Start Ask the AI to write table-driven unit tests for your Gin handler and an integration test for the repository using testcontainers.

Frequently Asked Questions about golang-gin-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Gin handlers with httptest in Go?▼

Create a bare router with gin.New(), wire a mock service implementing the service interface, and call router.ServeHTTP with an httptest.ResponseRecorder. Assert on w.Code for the status and unmarshal w.Body to verify the JSON response shape.

How to write integration tests for Go with testcontainers?▼

Add the //go:build integration tag, start a PostgreSQL container in TestMain with testcontainers-go, connect via GORM, and run AutoMigrate. Run tests with go test -tags=integration and clean state between tests using TRUNCATE in t.Cleanup.

Should I use errors.As or errors.Is for testing Go errors?▼

Use errors.As to unwrap typed errors like *domain.AppError and inspect fields such as the HTTP status code. errors.Is only works reliably if the error type implements an Is() method, so errors.As is the safer default for typed application errors.

What is the difference between unit, integration, and e2e tests in Go?▼

Unit tests mock the layer below and run fast without external services. Integration tests use a real database via testcontainers to verify SQL behavior. E2e tests wire the full application in-process and verify critical user flows like register, login, and CRUD.

When should I not use t.Parallel() in Go tests?▼

Avoid t.Parallel() when tests share mutable state such as a database, files, or package-level variables. It is safe for stateless tests like table-driven handler validation tests where each subtest is independent.

How do I measure Gin handler performance with benchmarks?▼

Write a Benchmark function using testing.B with an httptest recorder and a mock service, then run go test -bench=. -benchmem -count=3. Use benchstat to compare results across commits and detect performance regressions in CI.