alex123098/my-dotfiles/go-testify
Claude Code and agent skill by alex123098/my-dotfiles
Trust tier 3
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
stretchr/testify patterns for Go tests — assert vs require, mock expectations, argument matchers, suites, and common pitfalls. Use when the codebase imports github.com/stretchr/testify and you need to write or review test assertions, mocks, or suites.
Install
npx vskill@latest install alex123098/my-dotfiles/go-testifySKILL.md
Procedure
- assert vs require: Both offer identical assertions.
assertrecords failure and continues — you see all failures at once.requirecallst.FailNow()— use for preconditions where continuing would panic (nil pointers after error, missing config). Rule:requirefor guards/setup,assertfor verifications. Useassert.New(t)/require.New(t)aliased asisandmustfor readability:is.Equal(a, b)/must.NoError(err). - Core Assertions: Always keep argument order
(expected, actual)— swapping produces backwards diffs.is.Equal(expected, actual)— DeepEqual + exact type.is.EqualValues— converts types first (int to int64).is.NoError(err)/is.Error(err),is.ErrorIs(err, sentinel)— walks the chain.is.Nil(obj)/is.NotNil(obj).is.True(cond)/is.False(cond).is.Empty(collection)/is.Len(collection, n).is.Greater(a, b)/is.Less(a, b).is.Contains(slice, item)/is.ElementsMatch(a, b)for unordered comparison.is.InDelta(a, b, eps)for float tolerance.is.JSONEq(json1, json2)for JSON ignoring whitespace/key order.is.Eventually(func() bool { ... }, timeout, interval)for async polling. - Mock Pattern: Embed
mock.Mockin your mock struct, implement interface methods withm.Called(args...):func (m *MockStore) Get(id int) (*User, error) { args := m.Called(id); return args.Get(0).(*User), args.Error(1) }. Set expectations in test:mockStore.On("Get", 42).Return(&User{Name: "alice"}, nil). ALWAYS verify withmockStore.AssertExpectations(t)at the end — without it, unmatched expectations silently pass. Uset.Cleanup(func() { mockStore.AssertExpectations(t) })to avoid forgetting. - Argument Matchers:
mock.Anything— matches any argument.mock.AnythingOfType("string")— matches any string.mock.MatchedBy(func(v any) bool)— custom predicate matching. Use these when the exact value isn't important for the test scenario. - Call Modifiers: Chain after
.Return(...):.Once()— expect exactly one call..Times(n)— expect n calls..Maybe()— optional call (use sparingly)..Not()— assert NOT called at all..Run(func(args mock.Arguments) { ... })— run logic when call happens (capture arguments)..Panic(val)— simulate panic return. - Return Value Helpers:
args.Get(0)returnsany— cast to concrete type.args.String(0)/args.Int(0)for typed extraction.args.Error(0)returnserror.args.Bool(0)returnsbool.args.Get(n)panics if index out of range — ensure your mock method declares the right number of return values. - Suite Patterns: Embed
suite.Suitefor shared setup:type MySuite struct { suite.Suite; db *MockDB; svc *Service }. Lifecycle:SetupSuite()once before all tests,SetupTest()before each test,TearDownTest()after each,TearDownSuite()once after all. Suite methods uses.Equal(),s.Require().NoError(). MUST have a launcher:func TestMySuite(t *testing.T) { suite.Run(t, new(MySuite)) }. Prefer table-driven subtests over suite-style for most cases — use suites primarily whenSetupTestoverhead is significant (DB setup, file fixtures).
Pitfalls
- Forgetting
AssertExpectations(t)— mock expectations are silently ignored if never verified. Uset.Cleanup(func() { m.AssertExpectations(t) })right after mock creation. - Swapped
(expected, actual)order in assertions — testify assumesEqual(expected, actual). Swapping produces backwards diff output. - Using
assertfor guard conditions wherenilwould cause a panic — userequireto halt immediately. - Missing
suite.Run(t, new(MySuite))— without the launcher, zero suite tests execute silently. - Comparing pointers with
is.Equal— compares addresses. Use.EqualExportedValuesor dereference. - Using
is.Equal(err, ErrNotFound)— fails on wrapped errors. Useis.ErrorIs(err, ErrNotFound)to walk the chain. - Mixing mock expectations with concrete types from previous test calls — always reset mocks in
SetupTestfor fresh expectations per test.
Verification
go test ./...passes with all mockAssertExpectationsverified.- No bare
err == sentinelcomparisons in test code — usesErrorIsinstead. - All preconditions use
require(notassert) — nil dereferences after failure are impossible. - Every mock method properly extracts return values via
args.Get(n)with correct type assertions. - Suite types have a corresponding
TestXxxSuite(t *testing.T)launcher function.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpi/.pi/agent/skills/go-testify/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/alex123098/my-dotfiles/go-testify)