Testing Anti-Patterns Guide

Identify testing anti-patterns in unit, integration, and end-to-end test suites.

Updated Nov 5, 2025
One-click install
npx skills add https://github.com/mikeyobrien/ghclip --skill testing-anti-patterns-guide
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Testing Anti-Patterns Guide
Source: https://github.com/mikeyobrien/ghclip/tree/main/.claude/skills/testing-anti-patterns
Command: npx skills add https://github.com/mikeyobrien/ghclip --skill testing-anti-patterns-guide

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This document identifies three foundational rules for effective testing and outlines five major anti-patterns to avoid.

Core Principles

The core guidance emphasizes that "Tests must verify real behavior, not mock behavior." Mocks are a means to isolate, not the thing being tested.

The document identifies five major anti-patterns:

  • Testing Mock Behavior: Asserting that mocks exist rather than verifying real component output represents a fundamental test failure.
  • Test-Only Methods: Adding methods like destroy() solely for test cleanup pollutes production code. Instead, place cleanup logic in dedicated test utilities.
  • Mocking Without Understanding: Over-mocking to "be safe" often breaks critical test logic by replacing methods whose side effects the test depends upon. Understanding dependency chains before mocking is essential.
  • Incomplete Mocks: Partial mock objects create false confidence—they pass tests while failing in real integration when code accesses unmocked fields.
  • Integration Tests as Afterthought: TDD prevents this by writing tests first, which naturally surfaces what actually needs mocking versus what should remain real.

Prevention Strategy

Test-Driven Development inherently prevents these anti-patterns by forcing developers to observe tests fail against real implementations before adding mocks. This process reveals whether mocks are genuinely needed or whether complex mock setups suggest reconsidering the testing approach entirely.

Quick Start

Review a failing test suite to identify mocks and anti-patterns, remove test-only methods, and ensure tests verify real behavior rather than mocks.

Frequently Asked Questions about Testing Anti-Patterns Guide

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why are my tests passing but the code fails in production?

Tests often pass because they verify mock behavior rather than real component output. Testing Mock Behavior—asserting mocks exist instead of validating actual results—is a fundamental anti-pattern. Ensure tests verify real behavior by removing unnecessary mocks and confirming assertions check actual functionality, not mock interactions.

How do I identify over-mocking in my test suite?

Over-mocking breaks tests by replacing methods whose side effects your test depends on. Identify Mocking Without Understanding by reviewing which dependencies you mock and why. Before mocking, trace dependency chains to confirm whether isolation is genuinely needed or whether the mock setup suggests reconsidering your testing approach entirely.

What's the best way to clean up test resources without polluting production code?

Avoid adding test-only methods like destroy() to production classes—this is the Test-Only Methods anti-pattern. Instead, place cleanup logic in dedicated test utilities. This keeps your codebase clean while ensuring proper resource teardown during test execution.

How can TDD prevent testing anti-patterns?

Test-Driven Development forces you to observe tests fail against real implementations before adding mocks. This process naturally reveals whether mocks are genuinely needed and prevents Integration Tests as Afterthought. Writing tests first surfaces what actually requires mocking versus what should remain real.

Why do partial mocks create false confidence?

Incomplete Mocks—partial mock objects that pass tests but fail in real integration—occur when code accesses unmocked fields. Tests pass locally while failing when dependencies behave differently in production. Ensure all mocked dependencies are fully configured or avoid mocking in favor of real instances.

How do I start fixing a failing test suite?

Review the test suite to identify mocks and anti-patterns, remove test-only methods, and ensure tests verify real behavior rather than mocks. Start by examining assertions to confirm they check actual component output, not mock interactions, then refactor mocks based on genuine isolation needs.