From test-principles
Principles for writing high-quality automated tests, based on Kent Beck, Kent C. Dodds, and t-wada. This skill MUST be used whenever writing or modifying implementation code — tests are part of implementation, not a separate step. Also use when writing tests, asked to "write tests", "add tests", "test this", reviewing or auditing existing tests, "review tests", "check test quality", "テストを書いて", or "テスト原則". If you are implementing a feature or fixing a bug, this skill applies.
How this skill is triggered — by the user, by Claude, or both
Slash command
/test-principles:test-principlesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
HOW to write tests (verification), not WHAT to test (validation). Which behaviors to cover is a human decision.
HOW to write tests (verification), not WHAT to test (validation). Which behaviors to cover is a human decision.
When implementing features or fixing bugs, write tests in the same change. Red → Green → Refactor:
AI agents tend to write all implementation first and bolt on tests afterward. Tests written this way unconsciously verify what was just built rather than what the code should do. Interleave instead.
If the user asks only for implementation without mentioning tests, still write them. Say so briefly: "Adding tests alongside the implementation to keep them behavior-focused."
Verify "a delicious nikujaga was made," not "the knife moved at 3cm intervals." If you only verify process, you might accidentally make curry and the tests still pass.
// Breaks if you refactor from reduce to for-loop
it('should call reduce internally', () => {
const spy = vi.spyOn(items, 'reduce');
applyDiscount(items, { type: 'fixed', value: 10 });
expect(spy).toHaveBeenCalled();
});
// Survives any internal refactor
it('fixed $10 discount on $100 item yields $90', () => {
const items = [{ name: 'Shirt', price: 100, quantity: 1 }];
expect(applyDiscount(items, { type: 'fixed', value: 10 })).toBe(90);
});
| Integration | Unit | |
|---|---|---|
| Behavior | Highest value | Useful, but misses integration bugs |
| Implementation | Don't test this | Don't test this |
The test name states the scenario and expected result. If the name is accurate, the assertion is almost redundant.
// Describes the mechanism — you must read the assertion to know the outcome
test('parses key=value pairs', () => { ... });
test('decodes URI-encoded characters', () => { ... });
// Describes the result — the reader knows the expected behavior from the name alone
test('?foo=1 returns { foo: "1" }', () => { ... });
test('%E5%BA%83 in value decodes to 広', () => { ... });
test('key without = maps to empty string', () => { ... });
test('20% coupon on $100 order results in $80 total', () => { ... });
'handles X' or 'processes Y' describes the implementation, not the behavior.
// Failure says "expected true, received false"
expect(result === 160).toBe(true);
expect(result).toBeTruthy();
// Failure says "expected 160, received 140"
expect(result).toBe(160);
Reserve toBeTruthy for functions whose contract is boolean.
describe('applyDiscount', () => {
describe('percentage discount', () => {
it('10% off $200 yields $180', () => { ... });
it('100% off yields $0', () => { ... });
});
describe('edge cases', () => {
it('empty cart returns 0 regardless of rule', () => { ... });
it('discount exceeding subtotal floors at 0', () => { ... });
it('maxDiscount caps a larger percentage', () => { ... });
});
});
Each test:
What's missing:
Flag issues with a concrete fix. For missing coverage, suggest specific test cases with expected values.
npx claudepluginhub kubosho/my-skills --plugin test-principlesProvides test design patterns, coverage strategies (80-100% targets), types (unit/integration/E2E), organization, and best practices for comprehensive test suites. Use for new suites, coverage improvement, or test design.
Provides a checklist for writing and reviewing tests: naming tests/files, designing data/fixtures/mocks, choosing assertions. Use for unit/integration/E2E tests.
Creates and manages unit and integration tests by analyzing codebase, auto-detecting test frameworks, and generating tests that follow project conventions.