golang-stretchr-testify

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

5|1|Updated Apr 14, 2026
One-click install
npx skills add https://github.com/omarluq/og-template --skill golang-stretchr-testify-omarluq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-stretchr-testify
Source: https://github.com/omarluq/og-template/tree/main/.agents/skills/golang-stretchr-testify
Command: npx skills add https://github.com/omarluq/og-template --skill golang-stretchr-testify-omarluq

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing reliable and readable tests in Go is hard without good helpers. This skill shows how to use stretchr/testify to enforce clear assertions, implement mocks, and organize tests into suites, reducing boilerplate and confusion.

Core Features & Use Cases

  • Assert and require helpers for readable verifications and fail-fast preconditions
  • Mocking with testify/mock and automatic verification of expectations
  • Test suites with setup/teardown and shared state
  • Advanced patterns like Eventually, JSONEq, and custom matchers for robust checks

Quick Start

Install testify, import assert and require, and write a simple test that validates a function's result and error using assertions.

Frequently Asked Questions about golang-stretchr-testify

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

FAQPage Schema
How do I write readable Go tests using testify assertions and requires?

Testify assertions and requires make Go tests readable by providing clear verification helpers. Use assert to continue checking after failures or require to fail fast on preconditions, reducing boilerplate in unit tests.

What is the difference between assert and require in Go testify?

The difference between assert and require in testify is failure behavior. Assert records failures and continues execution, while require stops the test immediately, making require ideal for fail-fast preconditions where subsequent logic depends on earlier success.

How do I create mocks for Go unit tests with testify/mock?

Testify/mock creates mocks by defining expected method calls and return values in your Go unit tests. It automatically verifies expectations, ensuring mock behavior matches the defined contract during test execution.

How do I use test suites in Golang for setup and teardown lifecycle management?

Testify suites provide structured lifecycle management in Golang tests by offering setup and teardown hooks. They organize tests with shared state, reducing boilerplate and ensuring consistent initialization across multiple test methods.

Does testify support advanced Go testing patterns like Eventually and JSONEq?

Testify supports advanced Go testing patterns including Eventually for polling asynchronous conditions and JSONEq for comparing JSON equality. It also supports custom matchers for robust, specialized verification checks.

What is the correct argument order when using testify assertions in Go?

The correct argument order for testify assertions in Go places the expected value first and the actual value second. Following this expected-then-actual pattern ensures clear error messages and maintains consistent verification logic.