一键导入
write-london-unit-test
Write unit tests following London School (mockist) TDD style.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write unit tests following London School (mockist) TDD style.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Improve comments and docs so they capture non-obvious intent, caller-visible contracts, invariants, and why-context; prune comments that only restate code. Use whenever writing or modifying code (any new or edited source file), not just on explicit cleanup requests. Triggers on "주석 정리", "주석 다듬기", "comment cleanup", "prune comments", "의도 정리", "clarify code intent", "intent comments", "contract docs", "API contract comments".
Write or update Java class-level Javadoc that documents responsibility, caller-visible boundaries, invariants, and thread-safety. Use when modifying API-facing or boundary-owning Java types, SPI and extension types, factories or coordinators that choose policy or workflow, abstract/interface contracts, or behavior-bearing core domain types whose responsibility, invariants, lifecycle, or threading are not obvious.
Write or update Java method-level Javadoc that documents caller-visible contracts, preconditions, postconditions, exceptions, externally visible side effects, and performance constraints. Use when modifying API, SPI, extension, or reused internal Java methods whose caller-visible or durable internal contract is non-obvious or not encoded by signatures, annotations, validation, or inherited documentation.
Write or update Java package-info.java documentation that defines package responsibility, durable boundaries, optional non-responsibilities, package-wide invariants, and extension points. Use when adding, renaming, moving, or splitting packages; changing responsibility across package boundaries; or creating/updating package-info.java for API-facing or shared packages with durable ownership rules.
Rebase current branch onto latest main/master.
Checkout main/master, pull latest, prune stale remotes.
| name | write-london-unit-test |
| description | Write unit tests following London School (mockist) TDD style. |
write-london-unit-test <class-or-method> — read target source first, then write tests.
Test what the method promises (its contract), not how it works internally. If the contract does not change, the test should not break.
Only the SUT is real. Every dependency is a mock.
Assert the SUT calls the right methods with the right arguments, the right number of times.
If the return value already proves the interaction happened, asserting on the return value is enough — skip the redundant verify().
No shared setup or class-level fields. Each test creates its own mocks and SUT inline.
Wire mocks via constructor. No reflection or annotation-driven injection.
When the production constructor hides a collaborator (a no-arg constructor that builds its own dependency), add a package-private constructor that takes the collaborator and keep the test in the same package, so the test injects a double through it — preferred over reflection, field injection, or static mocking.
public class Reader {
private final Parser parser;
public Reader() { // production
this(new RealParser());
}
Reader(Parser parser) { // package-private: test seam
this.parser = parser;
}
}
// test, in the same package:
Parser parser = mock();
Reader sut = new Reader(parser);
{action}Should{expectedResult}When{condition}
Each test follows this strict ordering:
Type x = mock(); lines, no stubbing yet)when(...).thenReturn(...) / thenThrow(...))The three phases (Given/When/Then) should be visually distinguishable by a blank line between them, without requiring comments to label them. Within Given, do not insert blank lines between the four sub-steps — the blank line is reserved for the phase boundary.
One level of test methods directly inside the test class.
Group related test methods under a nested class when a single class has many behaviors worth grouping (e.g., per-method or per-scenario).
Use a test data generator (Fixture Monkey, AutoFixture, faker). Only constrain fields relevant to the test — randomize everything else. Assert against generated values, not hardcoded ones.
Mock return values must also be randomized (UUID, Fixture Monkey, etc.). Extract all values into named variables before mock setup — never inline values inside given().willReturn() or willThrow().
@Mock, @InjectMocks, beforeEach, setUp). Construct explicitly per test.test prefix in method names.