/test-bdd:test-bddfrom test-bdd
Generate BDD-style tests with GIVEN/WHEN/THEN comments that check behavior through inputs and observable outputs, never implementation details — unit, integration, browser, or visual, for frontend, backend, or scripts. Use when asked to write or add tests for a file, module, endpoint, or script.
Ships in test-bdd. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Generate behavior-driven tests that check what the code does through its inputs and observable outputs, not how it does it. The same approach covers unit, integration, browser, and visual tests, in any language or framework the project already uses.
Test behavior through inputs and observable outputs, never internal implementation. Drive the code the way its callers do — call the function, render the component, send the request, run the script — and assert on what comes back or what a caller can see. Internal helpers still get covered, through the entry point that uses them. A test that breaks when the code is refactored without changing its behavior is testing implementation.
Read the code to find the cases (branches, guards, boundaries), but assert only through the outputs.
| Code kind | Drive it with | Assert on |
|---|---|---|
| Function / utility | Arguments | Return value, thrown error |
| Constants / config | Import | Exported values and the invariants between them |
| Component | Props, user events (click, type, keyboard) | Rendered text and roles, callback props fired, navigation |
| Hook / store | Its API, rendered in a test host | Returned state after each action |
| Browser (component, page) | Real keyboard and pointer, viewport size | Focus, element position and visibility, what CSS hides or shows |
| Visual (component, page) | A fixed state: props, theme, viewport, data | A screenshot compared with a reviewed baseline |
| HTTP handler / route | A request | Status, body, headers, and the side effect (row written, message queued) |
| Repository / DB query | Its methods against a real test database | Data returned, data persisted |
| Job / queue consumer / event | The message or trigger | State changed, messages emitted, retries or dead-lettering |
| CLI / script | Arguments, env vars, stdin, input files | Exit code, stdout/stderr, files written or changed |
Mock or fake only what the test cannot or should not run for real: the network, third-party APIs, the clock, randomness, and — in unit tests — slow collaborators such as the database. Prefer an in-memory fake or a test server over a mock that records calls. Never mock the unit's own internal modules just to check that one part called another.
Asserting that a mock was called (toHaveBeenCalledWith, assert_called_with) is fine only when that call is the output a caller cares about: a callback prop fired, an email sent, an outgoing request's parameters, an event published.
Say so in the THEN comment, so a reader knows why the call is the behavior.
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, gather that context and draft the case list — usually via a subagent. For a self-contained pure function or a constants file, reading it yourself is enough.
Use whatever subagent mechanism your environment offers (in Claude Code, the Explore or general-purpose agent via the Agent tool); without one, do the same survey yourself.
Give it a self-contained brief that includes:
testing, Playwright)Ask the agent to report the cases in the same describe / context / it shape with GIVEN/WHEN/THEN that the test file will use, each tagged with its level and the code that motivates it, plus open questions; read references/case-list.md for the report format to put in the brief.
When the report (or your own survey) is done:
Only then move on to generating the test file.
Decide which level(s) of tests to write for this code:
Default level by code kind:
| Code kind | Default level |
|---|---|
| Pure function / utility / constants | Unit |
| Hook / store / component logic with mockable deps | Unit |
| Component whose behavior depends on CSS or layout | Unit + Browser |
| Design-system component, page layout | Unit + Visual, plus Browser for what only a real engine can answer |
| Repository / DB query / HTTP client | Integration |
| HTTP handler / route / job / queue consumer | Integration |
| CLI / script | Integration (run it as a process), plus Unit for any pure logic it exports |
| Router, workflow, or multi-module orchestrator | Unit + Integration |
When the code kind matches a row, state the choice and why, and proceed — the user can redirect.
When it is ambiguous (e.g. a hook that also talks to the network), ask the user before generating (AskUserQuestion in Claude Code, or a plain message).
If the user already said which level they want, use that.
Write browser or visual tests only when the project already has a tool that runs a real browser (Vitest browser mode, Playwright, Storybook with Chromatic or a test runner, Loki, …); otherwise suggest one and ask before adding the dependency.
Until one exists, write the simulated-DOM tests and list the engine-only cases in your report as not covered; never write them against a simulated DOM, where they check nothing.
Pick the first level that can answer the question; each one down is slower and more fragile, so a case moves down only when the ones above cannot see the behavior.
:hover styles); native controls and APIs (date inputs, details/summary, dialog, inert, matchMedia, IntersectionObserver, ResizeObserver).A simulated DOM has no layout (every box measures 0×0) and doesn't load the app's CSS files by default.
The rest it imitates: the testing library moves focus on Tab by DOM order and tabindex, jsdom ignores @media and lacks matchMedia, dialog.showModal() and inert, and happy-dom evaluates media queries against a fixed default window.
An assertion about any of these checks the imitation, not the app.
React Native has no browser level unless it renders through react-native-web: its logic and rendering stay in the test renderer, and on-device behavior belongs to the end-to-end suite (Detox, Maestro). Don't propose a browser runner for it.
Don't write end-to-end tests unasked: when a case needs one, say so and suggest it for the project's end-to-end suite. When the user asks for one, the same BDD rules apply, in the project's end-to-end tool.
Unless the project already separates levels differently, give each level its own suffix, so each config includes its own files and excludes the rest:
x.test.ts(x) — unit (simulated DOM for web UI)x.integration.test.ts — integrationx.browser.test.tsx — browserx.visual.test.tsx — visualDefault globs match all of these at once (*.test.* in Vitest and Jest; *.test.* and *.spec.* in Playwright Test), so narrow each config's include and exclude the other levels, or a test runs twice, in the wrong environment, or not at all.
Where the runner fixes the file name, separate levels its own way instead: Go compiles only _test.go files as tests (use //go:build integration), and pytest collects only test_*.py and *_test.py (use markers or folders).
Put each test file next to the code it tests, so it moves and gets deleted with that code — unless the project keeps tests in a separate tree such as tests/; then follow it, since a file outside the runner's test paths is never collected.
Keep shared utilities (fixtures, fakes, render helpers) in a test folder.
"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 code in front of you:
undefined/None, NaN, -0, very large, very small, unicode, trailing whitespace)?if, switch, ?., ??, try/catch, early return.
Each branch is an edge case worth naming.null, or returns an unexpected shape?
Cover the ones the code handles, and at least one it doesn't (to document the contract).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.
The test name must read as should <observable behavior>, matching the THEN outcome.
For example: it('should redirect the user when the protected route is accessed unauthenticated'), or test_should_exit_with_code_2_when_the_input_file_is_missing where the runner uses function names.
Avoid vague ('works correctly') or implementation-focused ('calls setState') descriptions — see references/patterns.md → BDD Description Guidelines for more good/bad examples.
Inside the test body, use flexible GIVEN/WHEN/THEN/AND comments, in the language's comment syntax, to document the scenario the name describes; references/patterns.md → BDD Comment Combinations shows the other forms:
// GIVEN a user is authenticated
// AND the user has the admin role
// WHEN the admin panel loads
// THEN the user list should be displayed
// AND the audit link should be visible
Keep the case-list report's code anchors out of the committed test by default; the GIVEN/WHEN/THEN already documents intent.
Add one only when several sibling tests each pin a different branch, as a bare symbol or branch hint in brackets after the THEN, such as // [split('?')].
Never put a file:line (or the filename of a co-located unit) in a committed test: the line goes stale on the next edit above it and silently misleads.
Test libraries rename options, change defaults, deprecate helpers, and ship breaking changes; the code samples in references/ and the tool facts this skill states (defaults, file names, what a simulated DOM supports) can fall behind them.
Treat the samples as the shape of a good test — what to drive, what to assert, how to word GIVEN/WHEN/THEN — and the tool facts as claims to recheck, never as the current API.
Before writing calls or relying on a default, check what the installed versions offer:
package.json, pyproject.toml, go.mod, …).Use the newest API the installed version offers, experimental ones included, even where existing tests still use an older call. Never use a deprecated call; when the runner prints a deprecation warning, switch to the replacement it names before finishing. When a test relies on an experimental API, say so in your final report, so the user knows to recheck it on the next upgrade. Don't add an option that only restates a default.
catch, rejection, fallback branch, or non-zero exit in the source)The samples show the shape of each kind of test; take the exact API calls from the project's installed versions (see Use the Installed Library Versions).
references/case-list.md - Read when briefing a subagent (or drafting the case list yourself): the report format and how to annotate each casereferences/patterns.md - Read when writing frontend unit tests: React with vitest and testing-library (other frameworks' testing-library packages take the same shape), mock handling, and description guidelinesreferences/backend-and-scripts.md - Read when testing HTTP handlers, repositories with a real database, jobs, or scripts run as processes; TypeScript and Python examplesreferences/browser.md - Read when writing a browser test or adding a browser runner: what to check there, an example, and setup gotchasreferences/visual.md - Read when writing a visual test: making screenshots deterministic, choosing states, the quality of each capture, and handling baselinesreferences/examples.md - Read when you want a complete test file to model: a component, a hook, validators, and constantsWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub guillempuche/ai-skill-test-bdd --plugin test-bdd2 plugins ship this exact skill · first indexed Nov 18, 2026