This skill should be used when the user asks to "write tests", "fix failing tests", "improve test coverage" or "debug a flaky test", or reviews test quality.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Testing?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/dean0x-testing)
---
name: testing
description: This skill should be used when the user asks to "write tests", "fix failing tests", "improve test coverage" or "debug a flaky test", or reviews test quality.
user-invocable: false
allowed-tools: Read, Grep, Glob, AskUserQuestion
activation:
file-patterns:
- "**/*.test.*"
- "**/*.spec.*"
- "**/test/**"
- "**/tests/**"
- "**/__tests__/**"
exclude:
- "node_modules/**"
---
# Testing Patterns
## Iron Law
> **Tests validate behavior, not implementation.**
>
> A test should fail when behavior breaks, not when implementation changes. Mock at
> boundaries, not internals. Test the contract, not the code path. If tests are hard to
> write, the design is wrong — fix the architecture, not the tests.
## Testing Shapes
| Shape | Guidance |
|-------|---------|
| Pyramid | Many unit → fewer integration → fewest E2E |
| Trophy | Integration tests give best ROI for UI-heavy code |
| Google | 70% unit / 20% integration / 10% E2E |
## Test Doubles Taxonomy
| Type | When to Use | Example |
|------|------------|---------|
| **Dummy** | Fill unused parameters | `null`, empty object |
| **Stub** | Return canned data, no assertions | `getRate: () => 0.1` |
| **Spy** | Record calls, assert after | `jest.spyOn()` on public methods |
| **Mock** | Pre-programmed expectations | `expect(fn).toHaveBeenCalledWith(x)` |
| **Fake** | Working substitute (in-memory DB) | `InMemoryUserRepo` |
"Mock roles, not objects" — mock interfaces you own, never third-party internals.
## Test Design Red Flags
| Red Flag | Symptom | Root Cause | Fix |
|----------|---------|-----------|-----|
| Complex setup >10 lines | `beforeEach` with 6+ mocks | Too many dependencies | Split service; use fakes |
| Repetitive try/catch | Same pattern >3 times | API throws, not Result | Migrate to Result types |
| Nested mock structures | `mockDb.orders.create: jest.fn()` | Tight coupling | Extract interface; use fake |
| Spying on private methods | `jest.spyOn(obj as any, '_method')` | Tests implementation | Assert observable output |
```typescript
// VIOLATION: Tests private implementation
jest.spyOn(cart as any, 'updateTotal');
expect(spy).toHaveBeenCalled(); // Tests HOW
// CORRECT: Tests observable behavior
cart.addItem({ id: '1', price: 10 });
expect(cart.getTotal()).toBe(10); // Tests WHAT
```
## Property-Based Testing
State invariants; let the framework generate inputs and shrink failures:
```typescript
// fast-check: property must hold for all valid inputs
fc.assert(fc.property(fc.string(), (s) => decode(encode(s)) === s));
```
Use for: parsers/serializers, arithmetic, sorting, state machines.
## Flaky Tests
| Root Cause | Fix |
|-----------|-----|
| Async/timing races | Use fake timers; `await` all async ops |
| Order dependencies | Each test self-contained; fresh state |
| Shared mutable state | Reset in `afterEach`; use DI |
Quarantine flaky tests immediately — a suite that sometimes passes is worse than no suite.
## Coverage & Severity
| Severity | Criteria |
|----------|----------|
| **CRITICAL** | Tests don't verify behavior; critical paths untested; everything mocked |
| **HIGH** | Untested trust-boundary, data-loss, security or fail-closed path; flaky tests; slow (>10s); setup >10 lines |
| **MEDIUM** | Named edge case with no test; weak assertions; unclear AAA structure |
| **LOW** | Organization; naming clarity |
## Test Suite Safety
```typescript
{ fileParallelism: false, maxWorkers: 1, testTimeout: 10000 } // vitest / jest
```
## Extended References
| Reference | Contents |
|-----------|----------|
| `references/sources.md` | Bibliography (20 sources) |
| `references/violations.md` | Violations with citations |
| `references/patterns.md` | Correct patterns with citations |
| `references/detection.md` | Detection commands |
| `references/report-template.md` | Report format |
## Quality Gates
- [ ] Setup <10 lines
- [ ] Each new assertion would fail, not error, with the change reverted: its RED run counts, else a bad input or a temporary uncommitted revert of your own edit, never a stash
- [ ] A test for each acceptance-criterion behaviour; an edge-case test only for a named case
- [ ] Test names describe expected behavior
- [ ] Tests follow Arrange-Act-Assert structure
- [ ] No flaky patterns