/craft:tdd-workflow-principlesfrom craft
Guides cross-language TDD workflow with vertical-slice iterations, happy-path-first development, and interface design principles. Activates when building features test-first.
Ships in craft. 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.
None: SKILL.md is the whole skill.
The process below is language-agnostic. Test-runner commands and framework specifics (PHPUnit with Symfony container, vitest with NestJS modules, etc.) live in:
phpunit:php-tdd-workflowvitest:vitest-tdd-workflownode-test:node-test-conventions(a file importingnode:test, or a package whose test script runsnode --test)
For test-writing conventions (DAMP, AAA, spy vs mock, factories), see
testing-principles.
The key difference from textbook TDD: each iteration cuts across all layers (Controller / Domain / Repository / SPI / UI), not one layer at a time.
Iteration 1: Controller stub + first Domain behavior
↓
Iteration 2: Domain logic + Repository/SPI interface
↓
Iteration 3: Back to Controller → complete happy path
↓
Iteration 4: Edge case handling
↓
… continue until feature complete
Pattern: happy path first (Controller → Domain → SPI → back to Controller), then edge cases.
Writing all tests up front, then all implementation, is horizontal slicing. It produces brittle tests because:
Correct approach: vertical slices. One test → one minimal implementation → next test. Each cycle informs the next.
TDD only forces good interfaces if you let it. Before each iteration, ask:
What is the smallest public surface that would let me write this test?
Apply the deep modules principle (Ousterhout, A Philosophy of Software Design): small interface, deep implementation. A method with 1-2 parameters that does meaningful work is deeper than a method with 5 optional parameters that does the same thing.
{maxRetries, backoff, onRetry, logger, …}) grew because each new test needed a new knob → the interface is being pulled out of shape by its callers.When you spot these, pause the RED phase, redesign the interface (often: collapse parameters into a domain object, push a decision behind a private method, replace a flag with two methods), then re-write the test against the cleaner surface.
Testing through the public interface forces a good interface — but it's an effect, not an automatic outcome. The designer consciously decides the surface.
See also: craft:oop-principles (Tell-Don't-Ask, encapsulation), craft:ddd-principles (aggregates as natural deep modules).
Each iteration follows the strict cycle:
Never assume a test passes without running it.
At the end of each GREEN, the app must work in dev and prod. The most common mistake: tests pass but the app is broken.
| Check | Action |
|---|---|
| Template / view referenced? | Create the file (even empty) |
| Service injected? | Register in DI container / module |
| Repository used? | Implement or stub it |
| Module imported? | Add to parent module |
| Guard / middleware added? | Register in module / pipeline |
| Route added? | Verify routing (debug:router / equivalent) |
After each GREEN, look for duplication in both production code and tests.
it.each).Do NOT parameterize when assertions differ or setup is specific.
Merge only the same rule — never different rules that happen to share a shape. Two tests with the same Arrange/Act where only the data differs are the same rule at two data points (a date before vs after a threshold, a percentage above vs below a cutoff) — merge them. Two tests that hit the same code path but assert different business rules (field A is required vs field B is required) are not duplicates just because their structure looks similar — merging them behind a shared "state" object trades one assertion-per-concern for an omnibus test that fails without saying which rule broke.
Criterion: "is this the same rule tested on different inputs, or two rules that happen to produce a similarly-shaped test?" Only the first merges. When in doubt, keep them separate — an unmerged duplicate costs a few lines; a wrongly-merged test hides which rule regressed.
When something is broken, follow this order before any code change:
// Mock pattern — always passes regardless of real bug
service.method('x').willReturn(expectedResponse)
// Real pattern — exposes the bug
realService = createServiceWithRealDeps()
result = realService.method('x') // fails when real impl is broken
Whether a unit earns a test at all is testing-principles' call, not this table's: §2 lists what is not worth testing and §3 is the checklist that has to answer yes three times. Once a test is earned, §14 picks the level where its intent reads best — this table is the default starting point:
| Created | Default level |
|---|---|
| Domain model / specification / use case | Unit test |
| Controller / endpoint | Functional / E2E test |
| Repository / adapter | Integration test |
| Serialization carrying its own mapping or format rules | Serialization test — the plain data holder underneath earns none |
| The access rule a guard or middleware enforces | Wherever refusal is observable, usually functional |
testing-principles §3.If you rename an internal function/method (without changing its behavior) and a test breaks, that test was checking the implementation, not the behavior.
Rewrite it in terms of the public API before continuing. A test should only break when an observable behavior changes.
Concrete examples:
calculateTaxFromGross() from a public submit() → if submit_appliesTax breaks, it was coupled to the old internal layout.Collection<Order> with an OrderBook → if a test asserts on the internal type/structure instead of the business outcome, it breaks for no good reason.Controller to a UseCase → a functional test exercising the route should not break (same HTTP behavior).When you catch yourself saying one of these, treat it as a signal — not an excuse:
| Excuse | Reality |
|---|---|
| "Too simple to deserve a test" | Simple code breaks too. The test takes 30 seconds; the prod bug costs an hour. |
| "I'll test after, I'm just coding quickly right now" | Tests written after pass immediately. Passing immediately proves nothing — they may verify wrong behavior, implementation, or miss requirements. |
| "I already tested it manually" | Manual = ad-hoc, no trace, not replayable at the next refactor. Automated tests run the same way every time. |
| "Deleting X hours of code would be wasteful" | Sunk cost fallacy. Keeping code whose test you never saw fail is technical debt. Rewriting test-first takes X hours; picking up the bug three months later takes X × 5. |
| "I keep the code as reference and write the test after" | You'll adapt it instead of rediscovering the design. That's tests-after in disguise. Delete means delete. |
| "It's an exception, I know what I'm doing" | All exceptions look the same. If it happens twice, it's the rule, not the exception. |
| "The spec is clear, no need for RED" | RED isn't there to clarify the need; it's there to prove the test will catch a regression. Skipping RED means the test may pass by accident. |
If you catch yourself coding before the failing test → delete the code and start over test-first. No adaptation, no "reference".
| Phase | Verify |
|---|---|
| RED | Test fails for the right reason |
| GREEN | Test passes AND the app starts/runs |
| REFACTOR | Suite still passes, no new duplication |
| End of iteration | App works in dev and prod |
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub fabiensalles/claude-marketplace --plugin craft8 skills in this plugin
/code-style-principlesACTIVATE whenever writing or modifying production code in src/, in any language — this is the base layer these rules build on. ACTIVATE for code review, formatting questions, or 'coding standards'. Covers cross-language code style: control-structure spacing, early-return pattern, continue-vs-if/else in loops, explicit (non-truthy/falsy) checks, flattening nested null checks, parameter ordering. These rules go BEYOND standard linters. Language-specific syntax (no-empty in PHP, template literals in TS, nowdoc, optional chaining vs nullsafe) lives in php-code-conventions / ts-code-conventions, which apply on top of this skill rather than instead of it. DO NOT use for: language-specific syntax already covered by php-code-conventions / ts-code-conventions (see php:php-code-conventions + typescript:ts-code-conventions for PHP/TS specifics)./ddd-fp-principlesACTIVATE when modeling DDD aggregates, value objects and domain logic using functional patterns — immutable records, curried operations, Result types, validation/enrichment pipelines, handler orchestration. ACTIVATE for 'aggregate', 'smart constructor', 'make*', 'validation pipeline', 'enrichment', 'domain handler' in a functional context. Provides cross-language functional DDD principles. For OOP-style DDD (classes, decorators, module-bounded contexts) see craft:ddd-principles. Companion examples: ddd-ts-fp.Other plugins' skills for the same job