Skip to content
Back to skills

Collection

ASecurity

Apply London (mock-based) and Chicago (state-based) TDD schools. Use when practicing test-driven development or choosing testing style for your context.

  • 24 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 8, 2026
developmentjavascripttypescriptgojavatestingrefactoringapidatabase

Works with

  • api

Security analysis

A100/100

Pro scans all 21 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add mattnigh/skills_collection --skill collection --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Collection?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Collection
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mattnigh-collection-55418aeb/badge)](https://www.skillsdirectory.com/skills/mattnigh-collection-55418aeb)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tdd-london-chicago
description: 'Apply London (mock-based) and Chicago (state-based) TDD schools. Use when practicing test-driven development or choosing testing style for your context.'
category: development-practices
priority: high
tokenEstimate: 1100
agents: [qe-test-generator, qe-test-implementer, qe-test-refactorer]
implementation_status: optimized
optimization_version: 1.0
last_optimized: 2025-12-02
dependencies: []
quick_reference_card: true
tags: [tdd, testing, london-school, chicago-school, red-green-refactor, mocks]
---

# Test-Driven Development: London & Chicago Schools

<default_to_action>
When implementing TDD or choosing testing style:

1. IDENTIFY code type: domain logic → Chicago, external deps → London
2. WRITE failing test first (Red phase)
3. IMPLEMENT minimal code to pass (Green phase)
4. REFACTOR while keeping tests green (Refactor phase)
5. REPEAT cycle for next functionality

**Quick Style Selection:**

- Pure functions/calculations → Chicago (real objects, state verification)
- Controllers/services with deps → London (mocks, interaction verification)
- Value objects → Chicago (test final state)
- API integrations → London (mock external services)
- Mix both in practice (London for controllers, Chicago for domain)

**Critical Success Factors:**

- Tests drive design, not just verify it
- Make tests fail first to ensure they test something
- Write minimal code - no features beyond what's tested
  </default_to_action>

## Quick Reference Card

### When to Use

- Starting new feature with test-first approach
- Refactoring legacy code with test coverage
- Teaching TDD practices to team
- Choosing between mocking vs real objects

### TDD Cycle

| Phase        | Action               | Discipline                               |
| ------------ | -------------------- | ---------------------------------------- |
| **Red**      | Write failing test   | Verify it fails, check message is clear  |
| **Green**    | Minimal code to pass | No extra features, don't refactor        |
| **Refactor** | Improve structure    | Keep tests passing, no new functionality |

### School Comparison

| Aspect          | Chicago (Classicist)    | London (Mockist)           |
| --------------- | ----------------------- | -------------------------- |
| Collaborators   | Real objects            | Mocks/stubs                |
| Verification    | State (assert outcomes) | Interaction (assert calls) |
| Isolation       | Lower (integrated)      | Higher (unit only)         |
| Refactoring     | Easier                  | Harder (mocks break)       |
| Design feedback | Emerges from use        | Explicit from start        |

### Agent Coordination

- `qe-test-generator`: Generate tests in both schools
- `qe-test-implementer`: Implement minimal code (Green)
- `qe-test-refactorer`: Safe refactoring (Refactor)

---

## Chicago School (State-Based)

**Philosophy:** Test observable behavior through public API. Keep tests close to consumer usage.

```javascript
// State verification - test final outcome
describe('Order', () => {
  it('calculates total with tax', () => {
    const order = new Order();
    order.addItem(new Product('Widget', 10.0), 2);
    order.addItem(new Product('Gadget', 15.0), 1);

    expect(order.totalWithTax(0.1)).toBe(38.5);
  });
});
```

**When Chicago Shines:**

- Domain logic with clear state
- Algorithms and calculations
- Value objects (`Money`, `Email`)
- Simple collaborations
- Learning new domain

---

## London School (Mock-Based)

**Philosophy:** Test each unit in isolation. Focus on how objects collaborate.

```javascript
// Interaction verification - test method calls
describe('Order', () => {
  it('delegates tax calculation', () => {
    const taxCalculator = {
      calculateTax: jest.fn().mockReturnValue(3.5),
    };
    const order = new Order(taxCalculator);
    order.addItem({ price: 10 }, 2);

    order.totalWithTax();

    expect(taxCalculator.calculateTax).toHaveBeenCalledWith(20.0);
  });
});
```

**When London Shines:**

- External integrations (DB, APIs)
- Command patterns with side effects
- Complex workflows
- Slow operations (network, I/O)

---

## Mixed Approach (Recommended)

```javascript
// London for controller (external deps)
describe('OrderController', () => {
  it('creates order and sends confirmation', async () => {
    const orderService = { create: jest.fn().mockResolvedValue({ id: 123 }) };
    const emailService = { send: jest.fn() };

    const controller = new OrderController(orderService, emailService);
    await controller.placeOrder(orderData);

    expect(orderService.create).toHaveBeenCalledWith(orderData);
    expect(emailService.send).toHaveBeenCalled();
  });
});

// Chicago for domain logic
describe('OrderService', () => {
  it('applies discount when threshold met', () => {
    const service = new OrderService();
    const order = service.create({ items: [...], total: 150 });

    expect(order.discount).toBe(15); // 10% off > $100
  });
});
```

---

## Common Pitfalls

### ❌ Over-Mocking (London)

```javascript
// BAD - mocking everything
const product = { getName: jest.fn(), getPrice: jest.fn() };
```

**Better:** Only mock external dependencies.

### ❌ Mocking Internals

```javascript
// BAD - testing private methods
expect(order._calculateSubtotal).toHaveBeenCalled();
```

**Better:** Test public behavior only.

### ❌ Test Pain = Design Pain

- Need many mocks? → Too many dependencies
- Hard to set up? → Constructor does too much
- Can't test without database? → Coupling issue

---

## Agent-Assisted TDD

```typescript
// Agent generates tests in both schools
await Task(
  'Generate Tests',
  {
    style: 'chicago', // or 'london'
    target: 'src/domain/Order.ts',
    focus: 'state-verification', // or 'collaboration-patterns'
  },
  'qe-test-generator'
);

// Agent-human ping-pong TDD
// Human writes test concept
const testIdea = 'Order applies 10% discount when total > $100';

// Agent generates formal failing test (Red)
await Task('Create Failing Test', testIdea, 'qe-test-generator');

// Human writes minimal code (Green)

// Agent suggests refactorings
await Task('Suggest Refactorings', { preserveTests: true }, 'qe-test-refactorer');
```

---

## Agent Coordination Hints

### Memory Namespace

```
aqe/tdd/
├── test-plan/*        - TDD session plans
├── red-phase/*        - Failing tests generated
├── green-phase/*      - Implementation code
└── refactor-phase/*   - Refactoring suggestions
```

### Fleet Coordination

```typescript
const tddFleet = await FleetManager.coordinate({
  workflow: 'red-green-refactor',
  agents: {
    testGenerator: 'qe-test-generator',
    testExecutor: 'qe-test-executor',
    qualityAnalyzer: 'qe-quality-analyzer',
  },
  mode: 'sequential',
});
```

---

## Related Skills

- [agentic-quality-engineering](../agentic-quality-engineering/) - TDD with agent coordination
- [refactoring-patterns](../refactoring-patterns/) - Refactor phase techniques
- [api-testing-patterns](../api-testing-patterns/) - London school for API testing

---

## Remember

**Chicago:** Test state, use real objects, refactor freely
**London:** Test interactions, mock dependencies, design interfaces first
**Both:** Write the test first, make it pass, refactor

Neither is "right." Choose based on context. Mix as needed. Goal: well-designed, tested code.

**With Agents:** Agents excel at generating tests, validating green phase, and suggesting refactorings. Use agents to maintain TDD discipline while humans focus on design decisions.

Files in this skill

  • 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md15.1 KB
  • 17hz__nextjs-template__claude__skills__example-skill__SKILL.md316 B
  • 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md3.5 KB
  • 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md5.4 KB
  • 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md7.7 KB
  • 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md26.1 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md15.7 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md17.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md9.4 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md12.5 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md16.6 KB
  • 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md11.2 KB
  • 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md14.8 KB
  • 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md16.2 KB
  • 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md11.8 KB
  • 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md17.5 KB
  • 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md19.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md6.2 KB
  • 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md18.1 KB
  • 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md24.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.