golang-stretchr-testify

Write and review Go tests using stretchr/testify assertions, mocks, and suites.

2|Updated Mar 13, 2023
One-click install
npx skills add https://github.com/haipham22/golang-sample --skill golang-stretchr-testify-haipham22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-stretchr-testify
Source: https://github.com/haipham22/golang-sample/tree/main/.agents/skills/golang-stretchr-testify
Command: npx skills add https://github.com/haipham22/golang-sample --skill golang-stretchr-testify-haipham22

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you write and review Go tests that use stretchr/testify, reducing fragile assertions, hidden mock failures, and suite setup mistakes.

Core Features & Use Cases

  • Assertion guidance: choose assert or require correctly, keep argument order right, and compare errors the proper way.
  • Mocking guidance: define mocks, set expectations, match arguments, and verify calls with AssertExpectations.
  • Suite guidance: structure shared setup and teardown, use launcher functions, and apply require style inside suites.
  • Use case: improving a flaky service test that mixes preconditions and verifications, or fixing a mock that never verifies expected calls.

Quick Start

Ask the Skill to write or review a Go test that uses stretchr/testify for assertions, mocks, or suites.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
How do I use testify mocks to verify expected calls in Go tests?

Use testify mocks by defining a mock struct, setting method expectations with matchers, and calling AssertExpectations to verify expected calls were made during the test.

What is the difference between assert and require in testify?

The difference between assert and require is that assert logs failures and continues test execution, while require stops test execution immediately. Use require for checks like setup preconditions where continuing is impossible.

How do I structure testify suite setup and teardown in Go?

Structure testify suite setup and teardown by embedding suite.Suite, implementing SetupTest and TearDownTest methods, and launching with suite.Run to manage shared test lifecycle state across test cases.

Why does my testify mock never verify expected calls?

Your testify mock never verifies expected calls when AssertExpectations is missing or argument matchers fail to align. Review expectation definitions and matchers to ensure calls match the configured arguments.

Can I use testify EventuallyWithT for async polling in Go tests?

Yes, you can use testify EventuallyWithT for async polling in Go tests. It repeatedly executes assertions until they pass or a timeout occurs, making it suitable for testing asynchronous operations reliably.

What's the best way to compare error chains in testify assertions?

The best way to compare error chains in testify assertions is using assert.ErrorIs. It checks if a specific error exists within the error chain, ensuring reliable error matching without fragile equality checks.