Test bdd
Open-source AI coding skills for Claude Code, Cursor, Copilot, and AI agents
npx -y skills add guillempuche/ai-standards --skill test-bddAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 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.
What its author says it does
Copied from the file, not written here
Generate BDD-style test files that document behavior with GIVEN/WHEN/THEN comments and test only public API and observable outcomes. Language and framework agnostic, with patterns and examples tuned for TypeScript + vitest + testing-library (hooks, components, utilities, constants).
SKILL.md
9.2 KB, as published. Nobody here has run it
BDD Test File Generator
Generate behavior-driven test files that focus on public API and observable behavior.
Quick Start Workflow
- Read the source file to understand what needs to be tested
- Identify the public API - all exported functions, constants, hooks, or component props
- Check for existing test setup - look for
setup.ts,vitest.config.ts, or existing test files - Ask the user: unit, integration, or both? (see below)
- Delegate context + edge-case analysis to an agent (see below) — do not try to produce the full case list from the source file alone
- Review the agent's list with the user, prune/add cases, then
generate the test file using patterns from
references/patterns.md
Delegate Analysis to a Subagent
A single file rarely tells the full story: callers pass specific shapes, sibling files encode invariants, existing tests hint at conventions, and the bug that prompted the test may live in the git log. Before writing cases, spawn a subagent to gather that context and draft the case list.
Use the Explore agent (or general-purpose if deeper reasoning is needed)
via the Agent tool. Give it a self-contained brief that includes:
- The exact source path(s) being tested
- The testing level chosen in the previous step (unit / integration / both)
- The framework stack (e.g. vitest + testing-library, jest + supertest)
- The edge-case dimensions listed under Edge Cases: Analyze from Context — ask the agent to walk those dimensions against the actual code, not as a generic checklist
- An instruction to read callers, sibling modules, existing tests, and any obvious schema/constant files before proposing cases
Ask the agent to report back using a BDD-native shape — the same
describe / context / it nesting with GIVEN/WHEN/THEN that the generated
test file will use. This keeps review cheap (the scenarios map 1:1 to the
code you're about to write) and keeps the skill internally consistent.
Prefer spec style (matches vitest / jest / RSpec output):
describe <unit under test>
context <condition, state, or collaborator setup>
it <expected observable behavior>
GIVEN ...
WHEN ...
THEN ...
[src/foo.ts:42 — `if (!user)` branch]
it ...
context ...
Open questions
- <ambiguity the agent couldn't resolve from the code>
Use Gherkin-style Feature / Scenario instead only if the project already
uses Cucumber or a Gherkin runner.
Notes for the agent's report:
- Group scenarios by the code branch or collaborator state they exercise
(the
context), not by a "happy / edge / error" bucket — BDD treats them as a single flat list of scenarios. - Annotate each
itwith the code anchor that motivates it, so pruning is reviewable. Prefer a stable anchor — a named branch or symbol (`if (!user)` branch,split('?')) — overfile:line; line numbers drift even between the agent writing the report and you reading it. This annotation lives in the report, to be reviewed and discarded. - Cap report length (e.g. "under 400 lines") so it stays reviewable.
When the report comes back:
- Resolve the Open Questions with the user before generating code
- Drop any case the code doesn't actually distinguish
- Add anything the agent missed that you can justify from the source
Only then move on to generating the test file.
Ask: Unit, Integration, or Both?
Before generating anything, ask the user which level(s) of tests they want —
don't assume. Use AskUserQuestion (or a plain question if that tool isn't
available) with these choices, explained in terms of this file:
- Unit tests — exercise the module in isolation; collaborators (network, DB, other modules, timers, the DOM beyond what a single hook/component needs) are mocked or stubbed. Fast, many cases, focused on one unit's contract.
- Integration tests — let the real collaborators run and test how this module behaves inside its actual neighborhood (real DB/driver, real HTTP client hitting a test server, real router, multiple hooks/components composed together). Slower, fewer cases, focused on wiring and boundaries.
- Both — produce separate files (e.g.
foo.test.tsandfoo.integration.test.ts) so they can run under different configs.
Recommend a default based on the file:
| File kind | Default recommendation |
|---|---|
| Pure function / utility / constants | Unit |
| Hook / component with mockable deps | Unit |
| Repository / DB query / HTTP client | Integration |
| Router, workflow, or multi-module orchestrator | Both |
State the recommendation and why, but defer to the user's answer.
Edge Cases: Analyze from Context, Don't Use a Generic Checklist
"Empty string / null / zero" is a starting list, not the finish line. Before writing cases, read the source carefully and derive edge cases from what the code actually does. Check each of these against the file in front of you:
- Inputs and types — what does each parameter accept? For every type,
what are its degenerate values (empty, zero-length,
undefined,NaN,-0, very large, very small, unicode, trailing whitespace)? - Branches and guards — every
if,switch,?.,??,try/catch, early return. Each branch is an edge case worth naming. - Boundaries — off-by-one around lengths/indices, inclusive vs. exclusive ranges, min/max of numeric domains, first/last element behavior.
- State and time — initial render vs. after update, before vs. after async resolution, stale closures, cleanup on unmount, race between two in-flight requests, timers firing after teardown.
- Collaborator failures — what happens when the thing this code calls
throws, times out, returns
null, or returns an unexpected shape? Cover the ones the code handles, and at least one it doesn't (to document the contract). - Concurrency & ordering — duplicate events, rapid re-renders, out-of-order responses, double-submits.
- Authorization & identity — missing user, wrong role, expired token — wherever the code branches on identity.
- Environment — feature-flag on/off, locale/timezone, SSR vs. client, dev vs. prod env checks in the code.
Only include cases that the code's behavior actually distinguishes. Don't pad the file with cases the implementation treats identically — one test per observable behavior.
Core Principle
Test public API and observable behavior only, never internal implementation:
- Hooks/Components: Test user interactions, props, rendered output
- Functions/Utilities: Test inputs → outputs, not internal algorithm steps
- Constants: Test exported values are correct
Test Description Style
Use BDD-style descriptions with flexible GIVEN/WHEN/THEN/AND comments:
// Full form
// GIVEN an unauthenticated user
// WHEN the protected route is accessed
// THEN the user should be redirected
// With AND for multiple assertions
// GIVEN a user is authenticated
// WHEN the profile page loads
// THEN the username should be displayed
// AND the avatar should be visible
// Simple form (no WHEN needed)
// GIVEN an empty array
// THEN length should be zero
// Multiple conditions
// GIVEN a valid token
// AND the user has admin role
// WHEN accessing admin panel
// THEN access should be granted
Optional code anchor in the committed test
The motivating annotations from the agent's case-list report are for review
and pruning — by default keep them OUT of the committed test; the
GIVEN/WHEN/THEN already documents intent. Add an anchor only when an
assertion genuinely benefits from pointing at the code it locks in (e.g.
several sibling its each pin a different branch). When you do, use a
bare symbol or branch hint in brackets and nothing more:
// GIVEN a magic-link URL with the token in the query
// WHEN normalised
// THEN only the path survives
// [split('?')]
Never put a file:line in a committed test — the line goes stale on the
next edit above it and silently misleads. Drop the filename too when the
test is co-located with the unit it imports; it's redundant.
Coverage Requirements
- Primary success paths (happy path)
- Edge cases derived from the code (see Edge Cases: Analyze from Context above — not a generic "empty / null / zero" checklist)
- Error states (graceful error handling for every
catch, rejection, or fallback branch in the source) - All exported items
- For integration tests: the real wiring between this module and each collaborator it owns in production (don't re-test the collaborator itself)
References
references/patterns.md- Detailed test patterns and mock handlingreferences/examples.md- Complete example test files
Gives 0 of the 12 instructions most tdd skills give
Counted across 439 of the 443 authors here whose files we hold, read 2026-08-06
- write minimal code to pass the testin 302 of 439, across 218 files
- write a failing test firstin 176 of 439, across 112 files
- refactor code only after tests passin 171 of 439, across 101 files
- watch the test fail before writing codein 142 of 439, across 93 files
- test one behavior per testin 106 of 439, across 44 files
- refactor code while keeping tests greenin 99 of 439, across 86 files
- delete code written before testsin 98 of 439, across 54 files
- run tests after each refactor stepin 85 of 439, across 54 files
- Use real code instead of mocks unless unavoidablein 64 of 439, across 21 files
- confirm the test fails for the right reasonin 64 of 439, across 60 files
- reproduce bugs with a test before fixingin 53 of 439, across 36 files
- write tests before implementationin 48 of 439, across 39 files
Said here and by no other author read
- test only public API and observable outcomes
- ask the user to choose unit, integration, or both
- delegate context and edge-case analysis to a subagent
- review the agent case list with the user
- derive edge cases from actual code branches
- group scenarios by branch or collaborator state
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.