Test patterns
Reference for writing tests that actually protect against regressions — deep assertions over spies, table-driven tests, fixture hygiene, AAA structure. Use when writing, reviewing, or refactoring tests.From its SKILL.md
npx -y skills add atuljha23/holocron --skill test-patternsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.7 KB, 622 tokens by cl100k_base, as published. Nobody here has run it
Test patterns
A test's job is to fail when the behavior is wrong. Most mediocre tests pass whether the code is right or not.
Rules of thumb
Assert behavior, not implementation
Bad:
expect(spy).toHaveBeenCalled()
Good:
expect(response.body.status).toBe('completed')
expect(db.getUser(id).lastSeenAt).toBe(mockNow)
Spy-assertions fail on refactor and protect nothing. Behavior-assertions fail when the user-visible contract breaks.
One logical check per test
Many expect lines can add up to one assertion of one outcome — that's fine. What's not fine: one test that covers three unrelated behaviors so nobody can tell what broke when it fails.
Arrange-Act-Assert
it('rejects stale tokens', () => {
// Arrange
const token = signToken({ exp: yesterday() })
// Act
const result = verify(token)
// Assert
expect(result.ok).toBe(false)
expect(result.reason).toBe('expired')
})
Table-driven when the shape repeats
test.each([
['empty', '', 'required'],
['too short', 'ab', 'min_length'],
['has space', 'a b', 'invalid_char'],
['ok', 'alice', null],
])('validateUsername(%s=%j)', (_, input, expected) => {
expect(validateUsername(input).error).toBe(expected)
})
Fixtures > inline setup
If three tests set up the same validUser, extract it. If the setup is 20 lines, it's probably doing too much — mock less, use a real test DB.
Name tests as specs
The test name is a sentence the reader can understand without opening the code. it('rejects stale tokens') > it('test2').
Integration > unit for risk hotspots
Unit tests are great for pure logic. For "this endpoint returns the right data for this user" you want an integration test that hits a real database, a real router, and a real serializer. Mocks hide the bugs you actually ship.
Framework-specific pointers
Testing Library (React/Vue/Svelte)
- Query by role/label first,
getByTestIdlast. userEventoverfireEvent.- Avoid testing props/state; test what the user sees.
Pytest
- Use fixtures for setup, not class-level
setUp. parametrizefor table tests.-kand markers to target — CI can split suites.
Go
- Table tests with subtests:
t.Run(tt.name, func(t *testing.T) { ... }). t.Cleanupoverdeferfor teardown.
Jest/Vitest
describe.each+test.eachfor tables.- Avoid
toHaveBeenCalledwhen you can check the effect instead.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most test skills give in 622 tokens
Counted across 1,201 of the 2,096 authors here whose files we hold, read 2026-09-06
- Write a failing test before writing codein 43 of 1201, across 36 files
- Run the full test suitein 36 of 1201, across 35 files
- Test only one variable per experimentin 34 of 1201, across 17 files
- Read product marketing context before asking questionsin 34 of 1201, across 14 files
- Mock external dependenciesin 34 of 1201, across 30 files
- Define primary, secondary, and guardrail metricsin 33 of 1201, across 16 files
- Pre-determine sample size before startingin 31 of 1201, across 14 files
- Test behavior rather than implementationin 31 of 1201, across 29 files
- Formulate a hypothesis before designing a testin 30 of 1201, across 13 files
- Document every test hypothesis, variant, and resultin 29 of 1201, across 11 files
- Use descriptive test function namesin 25 of 1201, across 21 files
- Commit to the methodology without stopping earlyin 24 of 1201, across 8 files
Said here and by no other author read
- Use table-driven tests for repeating shapes
- Name tests as readable sentences
- Prefer integration tests for risk hotspots
- Query by role or label
- Use cleanup over defer for teardown
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.