{"id":"a4186000-4857-4c39-b32a-0bd38e5f9b2e","shortId":"HXwcFB","kind":"skill","title":"golang-stretchr-testify","tagline":"Comprehensive guide to stretchr/testify for Golang testing. Covers assert, require, mock, and suite packages in depth. Use whenever writing tests with testify, creating mocks, setting up test suites, or choosing between assert and require. Essential for testify assertions, mock e","description":"**Persona:** You are a Go engineer who treats tests as executable specifications. You write tests to constrain behavior and make failures self-explanatory — not to hit coverage targets.\n\n**Modes:**\n\n- **Write mode** — adding new tests or mocks to a codebase.\n- **Review mode** — auditing existing test code for testify misuse.\n\n# stretchr/testify\n\ntestify complements Go's `testing` package with readable assertions, mocks, and suites. It does not replace `testing` — always use `*testing.T` as the entry point.\n\nThis skill is not exhaustive. Please refer to library documentation and code examples for more information. Context7 can help as a discoverability platform.\n\n## assert vs require\n\nBoth offer identical assertions. The difference is failure behavior:\n\n- **assert**: records failure, continues — see all failures at once\n- **require**: calls `t.FailNow()` — use for preconditions where continuing would panic or mislead\n\nUse `assert.New(t)` / `require.New(t)` for readability. Name them `is` and `must`:\n\n```go\nfunc TestParseConfig(t *testing.T) {\n    is := assert.New(t)\n    must := require.New(t)\n\n    cfg, err := ParseConfig(\"testdata/valid.yaml\")\n    must.NoError(err)    // stop if parsing fails — cfg would be nil\n    must.NotNil(cfg)\n\n    is.Equal(\"production\", cfg.Environment)\n    is.Equal(8080, cfg.Port)\n    is.True(cfg.TLS.Enabled)\n}\n```\n\n**Rule**: `require` for preconditions (setup, error checks), `assert` for verifications. Never mix randomly.\n\n## Core Assertions\n\n```go\nis := assert.New(t)\n\n// Equality\nis.Equal(expected, actual)              // DeepEqual + exact type\nis.NotEqual(unexpected, actual)\nis.EqualValues(expected, actual)        // converts to common type first\nis.EqualExportedValues(expected, actual)\n\n// Nil / Bool / Emptiness\nis.Nil(obj)                  is.NotNil(obj)\nis.True(cond)                is.False(cond)\nis.Empty(collection)         is.NotEmpty(collection)\nis.Len(collection, n)\n\n// Contains (strings, slices, map keys)\nis.Contains(\"hello world\", \"world\")\nis.Contains([]int{1, 2, 3}, 2)\nis.Contains(map[string]int{\"a\": 1}, \"a\")\n\n// Comparison\nis.Greater(actual, threshold)     is.Less(actual, ceiling)\nis.Positive(val)                  is.Negative(val)\nis.Zero(val)\n\n// Errors\nis.Error(err)                     is.NoError(err)\nis.ErrorIs(err, ErrNotFound)      // walks error chain\nis.ErrorAs(err, &target)\nis.ErrorContains(err, \"not found\")\n\n// Type\nis.IsType(&User{}, obj)\nis.Implements((*io.Reader)(nil), obj)\n```\n\n**Argument order**: always `(expected, actual)` — swapping produces confusing diff output.\n\n## Advanced Assertions\n\n```go\nis.ElementsMatch([]string{\"b\", \"a\", \"c\"}, result)             // unordered comparison\nis.InDelta(3.14, computedPi, 0.01)                            // float tolerance\nis.JSONEq(`{\"name\":\"alice\"}`, `{\"name\": \"alice\"}`)             // ignores whitespace/key order\nis.WithinDuration(expected, actual, 5*time.Second)\nis.Regexp(`^user-[a-f0-9]+$`, userID)\n\n// Async polling\nis.Eventually(func() bool {\n    status, _ := client.GetJobStatus(jobID)\n    return status == \"completed\"\n}, 5*time.Second, 100*time.Millisecond)\n\n// Async polling with rich assertions\nis.EventuallyWithT(func(c *assert.CollectT) {\n    resp, err := client.GetOrder(orderID)\n    assert.NoError(c, err)\n    assert.Equal(c, \"shipped\", resp.Status)\n}, 10*time.Second, 500*time.Millisecond)\n```\n\n## testify/mock\n\nMock interfaces to isolate the unit under test. Embed `mock.Mock`, implement methods with `m.Called()`, always verify with `AssertExpectations(t)`.\n\nKey matchers: `mock.Anything`, `mock.AnythingOfType(\"T\")`, `mock.MatchedBy(func)`. Call modifiers: `.Once()`, `.Times(n)`, `.Maybe()`, `.Run(func)`.\n\nFor defining mocks, argument matchers, call modifiers, return sequences, and verification, see [Mock reference](./references/mock.md).\n\n## testify/suite\n\nSuites group related tests with shared setup/teardown.\n\n### Lifecycle\n\n```\nSetupSuite()    → once before all tests\n  SetupTest()   → before each test\n    TestXxx()\n  TearDownTest() → after each test\nTearDownSuite() → once after all tests\n```\n\n### Example\n\n```go\ntype TokenServiceSuite struct {\n    suite.Suite\n    store   *MockTokenStore\n    service *TokenService\n}\n\nfunc (s *TokenServiceSuite) SetupTest() {\n    s.store = new(MockTokenStore)\n    s.service = NewTokenService(s.store)\n}\n\nfunc (s *TokenServiceSuite) TestGenerate_ReturnsValidToken() {\n    s.store.On(\"Save\", mock.Anything, mock.Anything).Return(nil)\n    token, err := s.service.Generate(\"user-42\")\n    s.NoError(err)\n    s.NotEmpty(token)\n    s.store.AssertExpectations(s.T())\n}\n\n// Required launcher\nfunc TestTokenServiceSuite(t *testing.T) {\n    suite.Run(t, new(TokenServiceSuite))\n}\n```\n\nSuite methods like `s.Equal()` behave like `assert`. For require: `s.Require().NotNil(obj)`.\n\n## Common Mistakes\n\n- **Forgetting `AssertExpectations(t)`** — mock expectations silently pass without verification\n- **`is.Equal(ErrNotFound, err)`** — fails on wrapped errors. Use `is.ErrorIs` to walk the chain\n- **Swapped argument order** — testify assumes `(expected, actual)`. Swapping produces backwards diffs\n- **`assert` for guards** — test continues after failure and panics on nil dereference. Use `require`\n- **Missing `suite.Run()`** — without the launcher function, zero tests execute silently\n- **Comparing pointers** — `is.Equal(ptr1, ptr2)` compares addresses. Dereference or use `EqualExportedValues`\n\n## Linters\n\nUse `testifylint` to catch wrong argument order, assert/require misuse, and more. See `samber/cc-skills-golang@golang-lint` skill.\n\n## Cross-References\n\n- → See `samber/cc-skills-golang@golang-testing` skill for general test patterns, table-driven tests, and CI\n- → See `samber/cc-skills-golang@golang-lint` skill for testifylint configuration","tags":["golang","stretchr","testify","skills","samber","agent","agent-skills","antigravity","claude","claude-code","code","codex"],"capabilities":["skill","source-samber","skill-golang-stretchr-testify","topic-agent","topic-agent-skills","topic-antigravity","topic-claude","topic-claude-code","topic-code","topic-codex","topic-coding","topic-copilot","topic-cursor","topic-gemini","topic-gemini-cli-extension"],"categories":["cc-skills-golang"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/samber/cc-skills-golang/golang-stretchr-testify","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add samber/cc-skills-golang","source_repo":"https://github.com/samber/cc-skills-golang","install_from":"skills.sh"}},"qualityScore":"0.700","qualityRationale":"deterministic score 0.70 from registry signals: · indexed on github topic:agent-skills · 1725 github stars · SKILL.md body (5,746 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T18:53:03.129Z","embedding":null,"createdAt":"2026-04-18T20:32:29.853Z","updatedAt":"2026-05-18T18:53:03.129Z","lastSeenAt":"2026-05-18T18:53:03.129Z","tsv":"'-42':540 '/references/mock.md':476 '0.01':365 '1':291,300 '10':423 '100':401 '2':292,294 '3':293 '3.14':363 '5':379,399 '500':425 '8080':218 '9':386 'a-f0':383 'actual':244,250,253,261,304,307,345,378,599 'ad':77 'address':634 'advanc':351 'alic':370,372 'alway':112,343,442 'argument':341,465,594,645 'assert':13,36,42,103,142,148,154,229,236,352,407,563,604 'assert.collectt':411 'assert.equal':419 'assert.new':176,193,239 'assert.noerror':416 'assert/require':647 'assertexpect':445,572 'assum':597 'async':388,403 'audit':87 'b':356 'backward':602 'behav':561 'behavior':62,153 'bool':263,392 'c':358,410,417,420 'call':164,454,467 'catch':643 'ceil':308 'cfg':198,208,213 'cfg.environment':216 'cfg.port':219 'cfg.tls.enabled':221 'chain':325,592 'check':228 'choos':34 'ci':675 'client.getjobstatus':394 'client.getorder':414 'code':90,130 'codebas':84 'collect':274,276,278 'common':256,569 'compar':628,633 'comparison':302,361 'complement':96 'complet':398 'comprehens':5 'computedpi':364 'cond':270,272 'configur':684 'confus':348 'constrain':61 'contain':280 'context7':135 'continu':157,170,608 'convert':254 'core':235 'cover':12 'coverag':72 'creat':27 'cross':658 'cross-refer':657 'deepequ':245 'defin':463 'depth':20 'derefer':615,635 'diff':349,603 'differ':150 'discover':140 'document':128 'driven':672 'e':44 'emb':436 'empti':264 'engin':50 'entri':117 'equal':241 'equalexportedvalu':638 'err':199,203,317,319,321,327,330,413,418,537,542,582 'errnotfound':322,581 'error':227,315,324,586 'essenti':39 'exact':246 'exampl':131,505 'execut':55,626 'exhaust':123 'exist':88 'expect':243,252,260,344,377,575,598 'explanatori':68 'f0':385 'fail':207,583 'failur':65,152,156,160,610 'first':258 'float':366 'forget':571 'found':332 'func':188,391,409,453,461,515,525,549 'function':623 'general':667 'go':49,97,187,237,353,506 'golang':2,10,654,663,679 'golang-lint':653,678 'golang-stretchr-testifi':1 'golang-test':662 'group':479 'guard':606 'guid':6 'hello':286 'help':137 'hit':71 'ident':147 'ignor':373 'implement':438 'inform':134 'int':290,298 'interfac':429 'io.reader':338 'is.contains':285,289,295 'is.elementsmatch':354 'is.empty':273 'is.equal':214,217,242,580,630 'is.equalexportedvalues':259 'is.equalvalues':251 'is.error':316 'is.erroras':326 'is.errorcontains':329 'is.erroris':320,588 'is.eventually':390 'is.eventuallywitht':408 'is.false':271 'is.greater':303 'is.implements':337 'is.indelta':362 'is.istype':334 'is.jsoneq':368 'is.len':277 'is.less':306 'is.negative':311 'is.nil':265 'is.noerror':318 'is.notempty':275 'is.notequal':248 'is.notnil':267 'is.positive':309 'is.regexp':381 'is.true':220,269 'is.withinduration':376 'is.zero':313 'isol':431 'jobid':395 'key':284,447 'launcher':548,622 'librari':127 'lifecycl':485 'like':559,562 'lint':655,680 'linter':639 'm.called':441 'make':64 'map':283,296 'matcher':448,466 'mayb':459 'method':439,558 'mislead':174 'miss':618 'mistak':570 'misus':93,648 'mix':233 'mock':15,28,43,81,104,428,464,474,574 'mock.anything':449,532,533 'mock.anythingoftype':450 'mock.matchedby':452 'mock.mock':437 'mocktokenstor':512,521 'mode':74,76,86 'modifi':455,468 'must':186,195 'must.noerror':202 'must.notnil':212 'n':279,458 'name':182,369,371 'never':232 'new':78,520,555 'newtokenservic':523 'nil':211,262,339,535,614 'notnil':567 'obj':266,268,336,340,568 'offer':146 'order':342,375,595,646 'orderid':415 'output':350 'packag':18,100 'panic':172,612 'pars':206 'parseconfig':200 'pass':577 'pattern':669 'persona':45 'platform':141 'pleas':124 'point':118 'pointer':629 'poll':389,404 'precondit':168,225 'produc':347,601 'product':215 'ptr1':631 'ptr2':632 'random':234 'readabl':102,181 'record':155 'refer':125,475,659 'relat':480 'replac':110 'requir':14,38,144,163,223,547,565,617 'require.new':178,196 'resp':412 'resp.status':422 'result':359 'return':396,469,534 'returnsvalidtoken':529 'review':85 'rich':406 'rule':222 'run':460 's.equal':560 's.noerror':541 's.notempty':543 's.require':566 's.service':522 's.service.generate':538 's.store':519,524 's.store.assertexpectations':545 's.store.on':530 's.t':546 'samber/cc-skills-golang':652,661,677 'save':531 'see':158,473,651,660,676 'self':67 'self-explanatori':66 'sequenc':470 'servic':513 'set':29 'setup':226 'setup/teardown':484 'setupsuit':486 'setuptest':491,518 'share':483 'ship':421 'silent':576,627 'skill':120,656,665,681 'skill-golang-stretchr-testify' 'slice':282 'source-samber' 'specif':56 'status':393,397 'stop':204 'store':511 'stretchr':3 'stretchr/testify':8,94 'string':281,297,355 'struct':509 'suit':17,32,106,478,557 'suite.run':553,619 'suite.suite':510 'swap':346,593,600 't.failnow':165 'tabl':671 'table-driven':670 'target':73,328 'teardownsuit':500 'teardowntest':496 'test':11,24,31,53,59,79,89,99,111,435,481,490,494,499,504,607,625,664,668,673 'testdata/valid.yaml':201 'testgener':528 'testifi':4,26,41,92,95,596 'testify/mock':427 'testify/suite':477 'testifylint':641,683 'testing.t':114,191,552 'testparseconfig':189 'testtokenservicesuit':550 'testxxx':495 'threshold':305 'time':457 'time.millisecond':402,426 'time.second':380,400,424 'token':536,544 'tokenservic':514 'tokenservicesuit':508,517,527,556 'toler':367 'topic-agent' 'topic-agent-skills' 'topic-antigravity' 'topic-claude' 'topic-claude-code' 'topic-code' 'topic-codex' 'topic-coding' 'topic-copilot' 'topic-cursor' 'topic-gemini' 'topic-gemini-cli-extension' 'treat':52 'type':247,257,333,507 'unexpect':249 'unit':433 'unord':360 'use':21,113,166,175,587,616,637,640 'user':335,382,539 'userid':387 'val':310,312,314 'verif':231,472,579 'verifi':443 'vs':143 'walk':323,590 'whenev':22 'whitespace/key':374 'without':578,620 'world':287,288 'would':171,209 'wrap':585 'write':23,58,75 'wrong':644 'zero':624","prices":[{"id":"00220632-edb6-4981-b56b-d471e04388b8","listingId":"a4186000-4857-4c39-b32a-0bd38e5f9b2e","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"samber","category":"cc-skills-golang","install_from":"skills.sh"},"createdAt":"2026-04-18T20:32:29.853Z"}],"sources":[{"listingId":"a4186000-4857-4c39-b32a-0bd38e5f9b2e","source":"github","sourceId":"samber/cc-skills-golang/golang-stretchr-testify","sourceUrl":"https://github.com/samber/cc-skills-golang/tree/main/skills/golang-stretchr-testify","isPrimary":false,"firstSeenAt":"2026-04-18T21:55:24.104Z","lastSeenAt":"2026-05-18T18:53:03.129Z"},{"listingId":"a4186000-4857-4c39-b32a-0bd38e5f9b2e","source":"skills_sh","sourceId":"samber/cc-skills-golang/golang-stretchr-testify","sourceUrl":"https://skills.sh/samber/cc-skills-golang/golang-stretchr-testify","isPrimary":true,"firstSeenAt":"2026-04-18T20:32:29.853Z","lastSeenAt":"2026-05-07T22:40:27.725Z"}],"details":{"listingId":"a4186000-4857-4c39-b32a-0bd38e5f9b2e","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"samber","slug":"golang-stretchr-testify","github":{"repo":"samber/cc-skills-golang","stars":1725,"topics":["agent","agent-skills","ai","antigravity","claude","claude-code","code","codex","coding","copilot","cursor","gemini","gemini-cli-extension","openclaw","opencode","plugin","skills","skillsmp","vibe-coding"],"license":"mit","html_url":"https://github.com/samber/cc-skills-golang","pushed_at":"2026-05-18T17:36:00Z","description":"🧑‍🎨 A collection of Golang agentic skills that works","skill_md_sha":"b6443dbe771c2256e443b94a479ce96317c8f9c1","skill_md_path":"skills/golang-stretchr-testify/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/samber/cc-skills-golang/tree/main/skills/golang-stretchr-testify"},"layout":"multi","source":"github","category":"cc-skills-golang","frontmatter":{"name":"golang-stretchr-testify","license":"MIT","description":"Comprehensive guide to stretchr/testify for Golang testing. Covers assert, require, mock, and suite packages in depth. Use whenever writing tests with testify, creating mocks, setting up test suites, or choosing between assert and require. Essential for testify assertions, mock expectations, argument matchers, call verification, suite lifecycle, and advanced patterns like Eventually, JSONEq, and custom matchers. Trigger on any Go test file importing testify.","compatibility":"Designed for Claude Code or similar AI coding agents, and for projects using Golang."},"skills_sh_url":"https://skills.sh/samber/cc-skills-golang/golang-stretchr-testify"},"updatedAt":"2026-05-18T18:53:03.129Z"}}