go-testing

Guide writing and executing Go tests with table-driven tests and mocking.

2|1|Updated Nov 13, 2025
One-click install
npx skills add https://github.com/MolcajeteAI/plugin --skill go-testing-molcajeteai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-testing
Source: https://github.com/MolcajeteAI/plugin/tree/main/molcajete/skills/go-testing
Command: npx skills add https://github.com/MolcajeteAI/plugin --skill go-testing-molcajeteai

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill provides comprehensive guidance and best practices for writing, organizing, and executing tests in Go, ensuring code quality and reliability.

Core Features & Use Cases

  • Test Organization: Learn best practices for file structure, naming conventions, and using TestMain.
  • Mocking & Assertions: Understand interface-based mocks, httptest, and assertion libraries like testify.
  • Coverage & Benchmarking: Master coverage analysis and performance benchmarking to optimize code.
  • Use Case: You need to write robust unit tests for a new Go service, including setting up mocks for external dependencies and ensuring adequate test coverage.

Quick Start

Use the go-testing skill to write effective table-driven tests for a Go function.

Frequently Asked Questions about go-testing

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

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

Table-driven tests in Go use a slice of structs to define test cases, iterating through them to validate outputs. This standardizes test execution and ensures comprehensive coverage across multiple input scenarios.

What is the best way to mock external dependencies for Go unit tests?

Mocking external dependencies in Go unit tests is best achieved using interface-based mocks. By defining interfaces, you can substitute real implementations with mock objects to isolate and verify specific component behaviors.

How does httptest work for testing HTTP handlers in Go?

The httptest package simulates HTTP requests and records responses for testing Go handlers without a live server. It enables mock request generation and response recording to validate routing and payload handling.

Can I use testify for assertions and mocking in Go testing?

Yes, testify integrates with Go testing to provide assertion libraries and mocking capabilities. It streamlines test writing by offering expressive assertion functions and a mock package to simplify complex test setups.

How do I measure Go test coverage and run benchmarks?

Go test coverage is measured using standard library coverage flags, while benchmarking evaluates code performance. Running benchmarks alongside coverage analysis helps optimize both code reliability and execution speed.

Does testcontainers-go support database integration tests in Go?

Yes, testcontainers-go supports database integration tests by provisioning disposable Docker containers. This allows you to execute integration tests against real database instances, ensuring accurate environment validation.