/skraft:clean-architecture-testingfrom skraft
Guides where to place tests and which doubles to use in Clean Architecture solutions. Covers test project organization, layer-specific testing rules, and when to test value objects or constructors.
Ships in skraft. 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.
Defines where to test and with which doubles in a Clean Architecture solution. Language-agnostic. Does NOT redefine the TDD cycle — that is owned by outside-in-tdd.
Core principle: every test enters through one boundary and asserts at the next boundary. Choice of double follows the layer, not convenience.
REQUIRED SUB-SKILL: Use outside-in-tdd for the RED → SYNTHESIZE-GREEN → COMMIT cycle. This skill only routes you to the correct layer and doubles.
Default = Application-level acceptance test. Do NOT write Domain tests by default.
Extract a Domain test ONLY when a business rule:
NEVER test directly:
A test asserting new PolicyNumber("abc").value == "abc" is noise. It tests the compiler, not behavior.
Rule: exactly two test projects per bounded context, regardless of language.
| Test project | Targets | Contains |
|---|---|---|
<Context>.UnitTest | Domain + Application | Domain unit tests (rare, extracted rules) + Application acceptance tests (mocks on output gateways, in-memory fakes) |
<Context>.IntegrationTest | Infrastructure + API + Architecture | Infrastructure integration tests (real containers), API end-to-end tests (in-process app host), architecture tests |
| Ecosystem | UnitTest project | IntegrationTest project |
|---|---|---|
| .NET | tests/<Context>.UnitTest/ csproj | tests/<Context>.IntegrationTest/ csproj |
| Java (Maven / Gradle) | <context>-unit-test module | <context>-integration-test module |
| Python | tests/unit/ package | tests/integration/ package |
| React front end (Vitest) | tests/unit/ folder | tests/integration/ folder |
| TypeScript / Node | test/unit/ workspace | test/integration/ workspace |
One pair per bounded context. Shared helpers (fakes, builders) live in a separate non-test project (TestKit / tests-shared) referenced by both.
Test class folders and namespaces are named after the feature or behavior under test — never after the GitHub issue, story ID, or sprint.
| Wrong | Right |
|---|---|
EligibilityCheck/STORY-42/ | EligibilityCheck/ |
tests/OrderSubmission/issue-105/ | tests/OrderSubmission/ |
PlaceOrder/Sprint3/ | PlaceOrder/ |
One folder per feature or bounded behavior. The folder name answers "what does this test?" not "which ticket created it?"
| Wrong | Why |
|---|---|
| Single test project mixing unit + integration | Slow tests pollute the fast loop; developers start skipping the suite |
Splitting by production layer (*.Domain.Test, *.Application.Test, …) | Explodes project count, fights the boundary policy |
End-to-end app host test in UnitTest | API tests need full composition — belong in IntegrationTest |
Real container (DB / broker) in UnitTest | Breaks the <1 s suite promise |
Architecture scanner test in UnitTest | Architecture tests are a CI gate, not a development loop |
Third test project outside UnitTest / IntegrationTest | Creates a blind spot outside the two-speed suite; all tests belong to one of the two defined projects |
| Layer | Test type | Entry point | Doubles | Target speed | When to write |
|---|---|---|---|---|---|
| SharedKernel | None | — | — | — | Never (interfaces + base classes, no logic) |
| Domain | Pure unit (rare) | Policy / Domain Service / Specification | None (real objects) | <10 ms | Only for extracted complex rules |
| Application | Acceptance (sociable) | Command / Query handler or UseCase | Mocks on output gateways, hand-written in-memory fakes for stateful reuse | <100 ms | Default — one per Gherkin scenario |
| Infrastructure | Integration | Gateway adapter (repository, read service, message handler) | Real I/O via containers (DB, broker); external APIs via contract mock server | 1-5 s | One per adapter contract |
| API | End-to-end | HTTP endpoint via in-process app host | Real internal stack; contract mock server for downstream externals | 1-5 s | Walking skeleton + one happy path per endpoint |
| Architecture | Static analysis | Assembly / module scan | None | <1 s | One rule per constraint, CI gate |
| Role | Use for | Never for |
|---|---|---|
| Real domain object | Always, at every layer that touches Domain | — |
| Mock / stub on output gateway | Output gateways at Application level (repository, dispatcher, external service interfaces) | Domain objects, Application handlers |
| Hand-written in-memory fake | Reusable across many Application tests, stateful scenarios | One-off single-test cases |
| Real container (DB, broker) | Infrastructure adapter tests exclusively | Application or Domain tests |
| Contract mock server (for external APIs / brokers) | Infrastructure adapter tests against externals; API E2E with downstream externals | Internal domain logic, Application handlers |
| In-process app host (boots the full API) | API layer end-to-end tests exclusively | Application, Domain, Infrastructure |
| Architecture scanner | Architecture tests | Any behavioral test |
Pick one mocking library per solution and stick to it. Same for the app host factory. Mixing libraries across tests is a smell.
Full runnable examples: examples-dotnet.md (.NET), examples-java.md (Java / Spring Boot, Maven), examples-python.md (Python, pytest) and examples-react.md (React, Vitest). The roles are identical across languages.
given repository := mock of IOrderRepository
and dispatcher := mock of IDomainEventDispatcher
and handler := new PlaceOrderCommandHandler(repository, dispatcher)
when handler.handle(PlaceOrderCommand(id, "Alice"))
then repository received add(order where order.customerName == "Alice") exactly once
and dispatcher received dispatch(events containing OrderPlacedEvent) exactly once
given db := start Postgres container
and ctx := connect(db.connectionString) and migrate
and sut := new OrderRepository(ctx)
and order := Order.create(id, "Alice")
when sut.add(order)
then ctx.orders contains one row with customerName == "Alice"
given appHost := boot in-process app host
and client := appHost.createHttpClient()
when response := client.POST("/orders", { customerName: "Alice" })
then response.status == 201
and response.location is not null
assert each project references only its inner neighbour
(Api → Infrastructure → Application → Domain)
assert types in Domain depend only on Domain and the language core
assert types in Application depend only on Application, Domain and the language core
else fail with "Violations: ..."
The language core excludes I/O, network and persistence. Allow-list the business code: a rule that only forbids the other layers lets every framework through.
When an adapter (Infrastructure) or endpoint (API) talks to an external HTTP / gRPC / async API:
Out of scope for this skill — see api-contract-testing (upcoming) for the full pattern.
digraph which_layer {
node [shape=box];
change [shape=diamond, label="What is the change?"];
usecase [label="Use case orchestration\n(load/save/publish)"];
gateway [label="Gateway adapter\n(DB, HTTP, broker)"];
http [label="HTTP endpoint wiring"];
rule [label="Complex reusable rule\n(many edge cases)"];
boundary [label="Layer boundary rule"];
app_test [style=filled, label="Application acceptance test\n(mocks on output gateways)"];
infra_test [style=filled, label="Infrastructure integration test\n(real container / contract mock)"];
api_test [style=filled, label="API end-to-end test\n(in-process app host)"];
domain_test [style=filled, label="Domain unit test\n(pure)"];
arch_test [style=filled, label="Architecture test\n(static scan)"];
change -> usecase -> app_test;
change -> gateway -> infra_test;
change -> http -> api_test;
change -> rule -> domain_test;
change -> boundary -> arch_test;
}
Extended tree with tie-breakers: doubles-decision-tree.md.
| Anti-pattern | Fix |
|---|---|
Testing new ValueObject(x).value == x | Delete. Covered by usage in Application test. |
| Mocking a domain object | Use the real aggregate. Mock only output gateways. |
| Real container in an Application-level test | Move to Infrastructure layer or use an in-memory fake. |
| Shared global container across test classes | One container per test class, isolated lifecycle. |
| In-process app host used to test a handler | Switch to an Application-level test with mocks. |
| No architecture test guarding layer references | Add the rule. Layer discipline must be enforced by CI, not reviews. |
| Architecture test that only forbids the other layers | Allow-list what Domain and Application may depend on; a framework or an I/O client passes a layer-only rule. |
| In-memory fake DB provider used as Infrastructure test | Infrastructure tests MUST use the real provider via real container. In-memory providers silently accept invalid SQL. |
| One acceptance test covers 5 rules | Split: one Gherkin scenario = one test. |
| Duplicating acceptance coverage with a Domain test on the same rule | Delete the Domain test unless the rule was extracted. |
These thoughts signal you're about to violate the policy:
All of these mean: stop and re-read the table. Coverage is not the goal. Behavior at the correct boundary is.
TestClient, import-linter)references/architecture-rules.md (opens in a new tab)references/doubles-decision-tree.md (opens in a new tab)references/examples-dotnet.md (opens in a new tab)references/examples-java.md (opens in a new tab)references/examples-python.md (opens in a new tab)references/examples-react.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub sebastiendegodez/skraft-plugin --plugin skraft44 skills in this plugin
/acceptance-review-criteriaUse when reviewing DISTILL artefacts (Gherkin scenarios, test plans, implementation plans) for quality, completeness, and alignment. Contains the gate definitions and scoring rubric for the acceptance-designer-reviewer lenses./adr-eligibility-gateUse when deciding WHETHER a candidate architectural choice deserves an architecture decision record, before any record is drafted: a story enters DESIGN with a list of candidate choices, a reviewer flags ADR inflation, or someone asks "should I write an ADR for X?", "how many ADRs does this story need?", "is this ADR-worthy?", "this feels like too many ADRs", "disambiguate baseline from decision". Runs a baseline-vs-decision gate over each candidate and returns ELIGIBLE or NOT ELIGIBLE with the baseline, convention or architecture test that already covers it. Do NOT use when the decision is already settled and the user asks for the record to be written, when the request is about the ADR template, status transitions, superseding or lifecycle, or when the question is which pattern to adopt — those belong to architecture-decisions and architecture-patterns.
/adversarial-review-lensesUse when reviewing a phase artifact — a discovery brief, a plan, a design, an acceptance specification, or a slice reported as delivered — and the review has to end in a defensible pass-or-block verdict rather than a list of remarks. Covers judging whether the artifact covers everything that fed into it, whether it matches the business intent, whether it holds together internally, and what it puts at risk downstream, then weighing those into a single call. Not for routine code review of an ordinary change./architecture-decisionsUse when documenting architecture decisions as ADRs, evaluating trade-offs between alternatives, or managing the lifecycle of existing decisions. Covers ADR template, status transitions, consequence analysis, and quality criteria./architecture-patternsUse when selecting architecture patterns for a new feature, performing Event Modeling, defining bounded contexts, choosing DDD tactical patterns, evaluating pattern fitness, or understanding how patterns compose. Covers Event Modeling methodology, DDD strategic design, DDD tactical patterns, Clean Architecture, CQRS, and Event Sourcing./architecture-review-criteriaUse when reviewing DESIGN artefacts (event models, ADRs, component diagrams, context maps, interface contracts) for quality, DDD compliance, and architectural correctness. Contains gate definitions and scoring rubric for the solution-architect-reviewer lenses.Other plugins' skills for the same job