golang-testing

Guide Go testing with testify, goleak, and synctest patterns.

Updated May 4, 2026
One-click install
npx skills add https://github.com/VIethoangnguyenle/nexus-enterprise --skill golang-testing-viethoangnguyenle
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-testing
Source: https://github.com/VIethoangnguyenle/nexus-enterprise/tree/main/.agent/skills/golang-testing
Command: npx skills add https://github.com/VIethoangnguyenle/nexus-enterprise --skill golang-testing-viethoangnguyenle

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and scripts (resource) components.

What problem does it solve?

This Skill addresses the challenge of creating effective and maintainable testing strategies for Go projects, ensuring reliable code through comprehensive testing practices.

Core Features & Use Cases

  • Guides on writing unit, integration, and end-to-end tests for various Go components including HTTP handlers and database interactions.
  • Provides best practices, such as using t.Parallel(), goleak for goroutine leak detection, and mock interfaces, to improve test quality and reliability.
  • Use Case: You need to verify that a web service correctly handles requests and interacts with resources without leaks or flaky tests. Apply this Skill to structure tests that are fast, isolated, and maintainable.

Quick Start

Use this Skill to learn how to write table-driven tests for your Go functions and how to set up mocks with testify.

Frequently Asked Questions about golang-testing

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

FAQPage Schema
How do I write table-driven unit tests in Go?

Table-driven unit tests in Go use struct slices to define input and expected output, iterating through them to execute test logic. This pattern keeps test suites maintainable, isolated, and fast for verifying function behavior.

What's the best way to mock interfaces in Go testing?

Mocking interfaces in Go testing is best achieved using the testify framework to generate and assert mock behavior. This ensures isolated component testing by simulating dependencies like database interactions or HTTP handlers without live connections.

How does goleak detect goroutine leaks in Go tests?

Goleak detects goroutine leaks by verifying that all goroutines spawned during a test exit before the test completes. Integrating goleak ensures robust test suites by preventing hidden resource leaks that cause flaky tests or performance degradation.

Can I use t.Parallel() to speed up integration tests in Go?

Yes, using t.Parallel() speeds up integration tests in Go by running them concurrently across multiple CPU cores. This practice isolates test execution and significantly reduces overall test suite duration for reliable web service validation.

When should I use synctest for Go testing?

Synctest is used for Go testing when you need to coordinate and control goroutine scheduling during test execution. It ensures robust test suites by validating concurrency logic and preventing race conditions in complex integration scenarios.

Does this Skill cover end-to-end testing for HTTP handlers?

Yes, this Skill covers end-to-end testing for HTTP handlers, providing comprehensive guidelines for verifying web service request handling and resource interactions. It emphasizes test quality, reliability, and performance correctness across all testing scenarios.