testing-anti-patterns
Reviews test code to identify and fix common testing anti-patterns including flaky tests, over-mocking, brittle assertions, test interdependency, and hidden test logic. Flags bad patterns, explains the specific defect, and provides corrected implementations. Use when reviewing test code, debugging intermittent or unreliable test failures, or when the user mentions flaky tests, test smells, brittle tests, test isolation issues, mock overuse, slow tests, or test maintenance problems.
Best use case
testing-anti-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Reviews test code to identify and fix common testing anti-patterns including flaky tests, over-mocking, brittle assertions, test interdependency, and hidden test logic. Flags bad patterns, explains the specific defect, and provides corrected implementations. Use when reviewing test code, debugging intermittent or unreliable test failures, or when the user mentions flaky tests, test smells, brittle tests, test isolation issues, mock overuse, slow tests, or test maintenance problems.
Teams using testing-anti-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/anti-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How testing-anti-patterns Compares
| Feature / Agent | testing-anti-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Reviews test code to identify and fix common testing anti-patterns including flaky tests, over-mocking, brittle assertions, test interdependency, and hidden test logic. Flags bad patterns, explains the specific defect, and provides corrected implementations. Use when reviewing test code, debugging intermittent or unreliable test failures, or when the user mentions flaky tests, test smells, brittle tests, test isolation issues, mock overuse, slow tests, or test maintenance problems.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Testing Anti-Patterns
You are identifying and avoiding common testing anti-patterns.
## Review Workflow
Follow these steps when reviewing test code:
1. **Run tests in isolation** — Verify each test passes independently (no shared state, no ordering dependency).
2. **Check for patterns below** — Scan for each anti-pattern in the checklist; flag every match with the specific defect.
3. **Apply refactoring strategy** — Use the refactoring strategies section to select and apply the appropriate fix.
4. **Verify the test still fails when code breaks** — After fixing, confirm the corrected test catches real regressions (remove or stub the implementation to confirm a failure occurs).
## Critical Anti-Patterns
### 1. The Liar - Tests That Always Pass
**Problem:** Test passes even when the code is broken.
```typescript
// BAD - Always passes because it tests nothing meaningful
it('should process data', () => {
const result = processData(input);
expect(result).toBeDefined(); // Too weak
});
// GOOD - Actually verifies behavior
it('should transform input to uppercase', () => {
const result = processData({ text: 'hello' });
expect(result.text).toBe('HELLO');
});
```
**Detection:** Remove or break the implementation - test should fail.
### 2. The Giant - Tests Too Large
**Problem:** Single test covers too many behaviors.
```typescript
// BAD - Tests multiple things
it('should handle user registration', async () => {
const user = await register(userData);
expect(user.id).toBeDefined();
expect(user.email).toBe(userData.email);
expect(user.password).toBeUndefined();
expect(sendEmail).toHaveBeenCalled();
expect(createProfile).toHaveBeenCalled();
// ... 20 more assertions
});
// GOOD - Focused tests
it('should create user with provided email', async () => {
const user = await register(userData);
expect(user.email).toBe(userData.email);
});
it('should send welcome email on registration', async () => {
await register(userData);
expect(sendEmail).toHaveBeenCalledWith(
expect.objectContaining({ type: 'welcome' })
);
});
```
**Fix:** One test, one logical assertion concept.
### 3. The Inspector - Testing Implementation Details
**Problem:** Test breaks when implementation changes, even if behavior is correct.
```typescript
// BAD - Tests internal implementation
it('should use QuickSort for sorting', () => {
const sorter = new Sorter();
const spy = jest.spyOn(sorter, '_quickSort');
sorter.sort([3, 1, 2]);
expect(spy).toHaveBeenCalled();
});
// GOOD - Tests behavior/output
it('should return sorted array', () => {
const sorter = new Sorter();
expect(sorter.sort([3, 1, 2])).toEqual([1, 2, 3]);
});
```
**Fix:** Test what the code does, not how it does it.
### 4. The Mockery - Over-Mocking
**Problem:** Too many mocks make tests meaningless.
```typescript
// BAD - Everything is mocked, test proves nothing
it('should calculate price', () => {
const mockProduct = { getPrice: jest.fn().mockReturnValue(100) };
const mockDiscount = { apply: jest.fn().mockReturnValue(80) };
const mockTax = { calculate: jest.fn().mockReturnValue(8) };
const total = calculateTotal(mockProduct, mockDiscount, mockTax);
expect(total).toBe(88); // Just testing mock arithmetic
});
// GOOD - Use real objects where feasible
it('should apply 20% discount to price', () => {
const product = new Product({ price: 100 });
const discount = new PercentageDiscount(20);
const total = calculateTotal(product, discount);
expect(total).toBe(80);
});
```
**Fix:** Only mock external dependencies and side effects.
### 5. The Flaky Test - Random Failures
**Problem:** Test sometimes passes, sometimes fails.
Common causes:
- **Time-dependent logic**
- **Race conditions in async code**
- **Shared mutable state**
- **External dependencies**
```typescript
// BAD - Depends on current time
it('should show recent items', () => {
const item = { createdAt: new Date() };
expect(isRecent(item)).toBe(true);
});
// GOOD - Control the time
it('should show items from last 24 hours', () => {
const now = new Date('2024-01-15T12:00:00Z');
jest.setSystemTime(now);
const recent = { createdAt: new Date('2024-01-15T00:00:00Z') };
const old = { createdAt: new Date('2024-01-13T00:00:00Z') };
expect(isRecent(recent)).toBe(true);
expect(isRecent(old)).toBe(false);
});
```
### 6. The Slow Poke - Unnecessarily Slow Tests
**Problem:** Tests take too long to run.
```typescript
// BAD - Real network call
it('should fetch user data', async () => {
const response = await fetch('https://api.example.com/users/1');
const user = await response.json();
expect(user.name).toBeDefined();
});
// GOOD - Mocked network
it('should parse user response', async () => {
mockFetch.mockResolvedValue({
json: () => Promise.resolve({ id: 1, name: 'Test User' })
});
const user = await fetchUser(1);
expect(user.name).toBe('Test User');
});
```
**Target:** Unit tests < 100ms, Integration tests < 1s.
### 7. The Chain Gang - Test Dependency
**Problem:** Tests depend on other tests running first.
```typescript
// BAD - Tests must run in order
describe('User operations', () => {
let userId;
it('should create user', () => {
userId = createUser(); // Sets state for next test
expect(userId).toBeDefined();
});
it('should update user', () => {
updateUser(userId, newData); // Depends on previous test
expect(getUser(userId).name).toBe(newData.name);
});
});
// GOOD - Each test is independent
describe('User operations', () => {
it('should create user', () => {
const userId = createUser();
expect(userId).toBeDefined();
});
it('should update user', () => {
const userId = createUser(); // Creates its own user
updateUser(userId, newData);
expect(getUser(userId).name).toBe(newData.name);
});
});
```
### 8. The Secret Catcher - Hidden Test Logic
**Problem:** Test logic is hidden in helpers or setup.
```typescript
// BAD - Assertions hidden in helper
function assertValidUser(user) {
expect(user.id).toBeDefined();
expect(user.email).toMatch(/@/);
expect(user.createdAt).toBeInstanceOf(Date);
// Many more hidden assertions
}
it('should create valid user', () => {
const user = createUser(data);
assertValidUser(user); // What is actually being tested?
});
// GOOD - Explicit assertions
it('should create user with email', () => {
const user = createUser(data);
expect(user.email).toBe(data.email);
});
```
## Anti-Pattern Detection Checklist
When reviewing tests, watch for:
- [ ] Tests without meaningful assertions
- [ ] Tests with more than 5-7 assertions
- [ ] Tests that mock everything
- [ ] Tests that access private methods/properties
- [ ] Tests with sleep/wait calls
- [ ] Tests that depend on test execution order
- [ ] Tests with complex setup that obscures intent
## Refactoring Strategies
1. **Too many assertions** → Split into multiple tests
2. **Over-mocking** → Use real implementations or fakes
3. **Flaky tests** → Control time, mock external calls
4. **Slow tests** → Mock I/O, parallelize independent tests
5. **Hidden logic** → Inline or clearly name helpers
## When to Delete Tests
Tests that:
- Always pass regardless of implementation
- Test third-party library behavior
- Are permanently flaky without fix
- Duplicate other tests exactly
- Test deprecated codeRelated Skills
test-patterns
Applies proven testing patterns — Arrange-Act-Assert (AAA), Given-When-Then, Test Data Builders, Object Mother, parameterized tests, fixtures, spies, and test doubles — to help write maintainable, reliable, and readable test suites. Use when the user asks about writing unit tests, integration tests, or end-to-end tests; structuring test cases or test suites; applying TDD or BDD practices; working with mocks, stubs, spies, or fakes; improving test coverage or reducing flakiness; or needs guidance on test organization, naming conventions, or assertions in frameworks like Jest, Vitest, pytest, or similar.
hypothesis-testing
Applies the scientific method to debugging by helping users form specific, testable hypotheses, design targeted experiments, and systematically confirm or reject theories to find root causes. Use when a user says their code isn't working, they're getting an error, something broke, they want to troubleshoot a bug, or they're trying to figure out what's causing an issue. Concrete actions include isolating failing components, forming and testing hypotheses, analyzing error messages, tracing execution paths, and interpreting test results to narrow down root causes.
find-skills
Discovers, searches, and installs skills from multiple AI agent skill marketplaces (400K+ skills) using the SkillKit CLI. Supports browsing official partner collections (Anthropic, Vercel, Supabase, Stripe, and more) and community repositories, searching by domain or technology, and installing specific skills from GitHub. Use when the user wants to find, browse, or install new agent skills, plugins, extensions, or add-ons; asks 'is there a skill for X' or 'find a skill for X'; wants to explore a skill store or marketplace; needs to extend agent capabilities in areas like React, testing, DevOps, security, or APIs; or says 'browse skills', 'search skill marketplace', 'install a skill', or 'what skills are available'.
red-green-refactor
Guides the red-green-refactor TDD workflow: write a failing test first, implement the minimum code to make it pass, then refactor while keeping tests green. Use when a user asks to practice TDD, write tests first, follow red-green-refactor, do test-driven development, write failing tests before code, or phrases like 'make the test pass', 'test coverage', or 'unit tests before implementation'.
verification-gates
Creates explicit validation checkpoints (verification gates) between project phases to catch errors early and ensure quality before proceeding. Use when the user asks about quality gates, milestone checks, phase transitions, approval steps, go/no-go decision points, or preventing cascading errors across a multi-step workflow. Produces acceptance criteria checklists, automated CI gate configurations, manual sign-off requirements, and conditional review rules for scenarios such as security changes, API changes, or database migrations.
task-decomposition
Breaks down complex software, writing, or research tasks into small, atomic, independently completable units with dependency graphs and milestone breakdowns. Use when the user asks to plan a project, decompose a feature, create subtasks, split up work, or needs help organizing a large piece of work into a step-by-step plan. Triggered by phrases like "break down", "decompose", "where do I start", "too big", "split into tasks", "work breakdown", or "task list".
design-first
Guides the creation of technical design documents before writing code, producing architecture diagrams, data models, API interface definitions, implementation plans, and multi-option trade-off analyses. Use when the user asks to plan a feature, architect a system, design an API, explore implementation approaches, or requests a technical design or spec before coding — especially for complex features involving multiple components, ambiguous requirements, or significant architectural changes.
skill-authoring
Creates and structures SKILL.md files for AI coding agents, including YAML frontmatter, trigger phrases, directive instructions, decision trees, code examples, and verification checklists. Use when the user asks to write a new skill, create a skill file, author agent capabilities, generate skill documentation, or define a skill template for Claude Code agents.
trace-and-isolate
Applies systematic tracing and isolation techniques to pinpoint exactly where a bug originates in code. Use when a bug is hard to locate, code is not working as expected, an error or crash appears with unclear cause, a regression was introduced between recent commits, or you need to narrow down which component, function, or line is faulty. Covers binary search debugging, git bisect for regressions, strategic logging with [TRACE] patterns, data and control flow tracing, component isolation, minimal reproduction cases, conditional breakpoints, and watch expressions across TypeScript, SQL, and bash.
root-cause-analysis
Performs systematic root cause analysis to identify the true source of bugs, errors, and unexpected behavior through structured investigation phases — not just treating symptoms. Use when a user reports a bug, crash, error, or broken behavior and needs to debug, troubleshoot, or investigate why something is not working; especially for complex or intermittent issues across multiple components. Applies the Five Whys method, hypothesis-driven testing, stack trace analysis, git blame/log evidence gathering, and causal chain documentation to isolate and confirm root causes before applying any fix.
structured-code-review
Performs a structured five-stage code review covering requirements compliance, correctness, code quality, testing, and security/performance. Each stage uses targeted checklists and categorized feedback (Blocker/Major/Minor/Nit) with actionable suggestions and rationale. Use when the user asks for code review, PR feedback, pull request review, or wants their code checked for bugs, style issues, or vulnerabilities — triggered by phrases like "review my code", "check this PR", "review my changes", "pull request review", or "code feedback".
parallel-investigation
Coordinates parallel investigation threads to simultaneously explore multiple hypotheses or root causes across different system areas. Use when debugging production incidents, slow API performance, multi-system integration failures, or complex bugs where the root cause is unclear and multiple plausible theories exist; when serial troubleshooting is too slow; or when multiple investigators can divide root-cause analysis work. Provides structured phases for problem decomposition, thread assignment, sync points with Continue/Pivot/Converge decisions, and final report synthesis.