writing-go-tests

Generate Go tests with mockery mocks and testify/require assertions.

2|Updated Aug 6, 2021
One-click install
npx skills add https://github.com/MrPointer/dotfiles --skill writing-go-tests-mrpointer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-go-tests
Source: https://github.com/MrPointer/dotfiles/tree/main/.claude/skills/writing-go-tests
Command: npx skills add https://github.com/MrPointer/dotfiles --skill writing-go-tests-mrpointer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill streamlines the process of writing effective and conventional Go tests, ensuring code quality and maintainability.

Core Features & Use Cases

  • Standardized Test Structure: Follows project-specific conventions for naming, assertions, and test organization.
  • Mocking Strategies: Guides the use of mockery for interface mocks and provides alternatives when mocks are unavailable.
  • Unit & Integration Testing: Offers patterns for both isolated unit tests and broader integration tests.

Quick Start

Use the writing-go-tests skill to generate a unit test for the InstallPackage function in the brew package.

Frequently Asked Questions about writing-go-tests

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

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

To write table-driven tests in Go using testify, define a slice of test cases with inputs and expected outputs, then iterate over them while applying assertion patterns with testify/require to validate results efficiently.

What's the best way to generate mocks for Go unit tests?

The best way to generate mocks for Go unit tests is using mockery to create interface mocks, ensuring isolated testing scenarios; alternatively, you can use other mock selection strategies when mockery is unavailable.

How do I structure unit and integration tests in a Go project?

Structure unit and integration tests in a Go project by following project-specific conventions for naming and test organization, separating isolated unit tests from broader integration tests to maintain code quality and maintainability.

Does mockery work with existing Go interfaces for generating test mocks?

Yes, mockery works with existing Go interfaces to generate test mocks by parsing interface definitions and producing mock implementations that can be used with testify/require assertions in your testing scenarios.

Why use testify/require instead of standard Go testing assertions?

Use testify/require instead of standard Go testing assertions because it provides stricter assertion patterns that immediately fail the test on errors, streamlining the process of writing effective and conventional Go tests.

Can I use this approach for both unit and integration testing in Go?

Yes, you can use this approach for both unit and integration testing in Go, as it offers standardized patterns for isolated unit tests using mocks and broader integration tests validating multiple components.