/comprehensive-testing
Complete testing strategy covering TDD workflow, test pyramid, unit/integration/E2E/property testing, framework best practices (Jest, Vitest, pytest), mock strategies, and CI integration. Use when writing tests, reviewing test quality, or establishing testing standards.
$ npx -y skills add majiayu000/spellbook --skill comprehensive-testing --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/comprehensive-testing
Context preview
The summary Claude sees to decide when to auto-load this skill.
Complete testing strategy covering TDD workflow, test pyramid, unit/integration/E2E/property testing, framework best practices (Jest, Vitest, pytest), mock strategies, and CI integration. Use when writing tests, reviewing test quality, or establishing testing standards.
SKILL.md
comprehensive-testing.SKILL.mdname: comprehensive-testing
description: Complete testing strategy covering TDD workflow, test pyramid, unit/integration/E2E/property testing, framework best practices (Jest, Vitest, pytest), mock strategies, and CI integration. Use when writing tests, reviewing test quality, or establishing testing standards.
allowed-tools: Read, Grep, Glob, Bash, Edit, Write
Comprehensive Testing
> Based on [Anthropic's Claude Code Best Practices](https://www.anthropic.com/engineering/claude-code-best-practices) and community patterns
Core Philosophy
> "Claude performs best when it has a clear target to iterate against—a test case provides concrete success criteria."
Testing is not about proving code works; it's about **designing code that is testable** and **documenting expected behavior**.
---
Test Pyramid
/\
/ \ E2E Tests (10%)
/----\ - Full user flows
/ \ - Slowest, most brittle
/--------\
/ \ Integration Tests (20%)
/------------\ - Component interaction
/ \ - Real dependencies
/----------------\
Unit Tests (70%)
- Single function/method
- Fast, isolated, many| Level | Speed | Scope | When to Use | |-------|-------|-------|-------------| | Unit | <10ms | Single function | All logic | | Integration | <1s | Multiple components | APIs, DB | | E2E | <30s | Full flow | Critical paths |
---
TDD Workflow (Anthropic Recommended)
The 6-Step Process
1. WRITE TESTS FIRST
↓
2. VERIFY TESTS FAIL
↓
3. COMMIT TEST SUITE
↓
4. IMPLEMENT CODE
↓
5. VERIFY WITH SUBAGENT
↓
6. COMMIT IMPLEMENTATION
Step 1: Write Tests First
Be EXPLICIT about TDD to avoid mock implementations:
"I want to implement [feature] using TDD.
First, write tests for [expected behavior] with these input/output pairs:
- Input: X → Expected: Y
- Input: A → Expected: B
Do NOT create any implementation yet."
Step 2: Verify Tests Fail
# Run tests and confirm they fail for the RIGHT reason
npm test # or pytest, go test, etc.
# Expected: "function not found" or "undefined"
# NOT: syntax error, wrong import
Step 3: Commit Test Suite
git add tests/
git commit -m "test: Add tests for [feature] (RED phase)"
Step 4: Implement Incrementally
"Now implement the code to make these tests pass.
Do NOT modify the tests.
Run tests after each change until all pass."
Claude will enter an autonomous loop:
Write code → Run tests → Analyze failures → Adjust → Repeat
Step 5: Verify with Subagent
"Use a subagent to independently verify the implementation:
- Is it overfitting to tests?
- Are edge cases handled?
- Is the code maintainable?"
Step 6: Commit Implementation
git add src/
git commit -m "feat: Implement [feature] (GREEN phase)"
---
Test Structure Patterns
AAA Pattern (Arrange-Act-Assert)
describe('UserService', () => {
it('should create user with valid email', async () => {
// Arrange - Setup test data and dependencies
const userRepo = new InMemoryUserRepository();
const service = new UserService(userRepo);
const input = { email: 'test@example.com', name: 'Test' };
// Act - Execute the code under test
const user = await service.create(input);
// Assert - Verify the results
expect(user.email).toBe('test@example.com');
expect(user.id).toBeDefined();
expect(await userRepo.findById(user.id)).toEqual(user);
});
});Given-When-Then Pattern
def test_order_total_with_discount():
"""
Given an order with items totaling $100
When a 20% discount is applied
Then the total should be $80
"""
# Given
order = Order()
order.add_item(Item(price=50))
order.add_item(Item(price=50))
# When
order.apply_discount(Percentage(20))
# Then
assert order.total == Money(80)---
Framework Best Practices
Jest / Vitest (JavaScript/TypeScript)
// Structure
describe('ModuleName', () => {
describe('methodName', () => {
it('should [expected behavior] when [condition]', () => {});
});
});
// Setup/Teardown
beforeAll(async () => { /* one-time setup */ });
beforeEach(() => { /* per-test setup */ });
afterEach(() => { /* per-test cleanup */ });
afterAll(async () => { /* one-time cleanup */ });
// Async testing
it('handles async operations', async () => {
const result = await asyncFunction();
expect(result).toBe(expected);
});
// Error testing
it('throws on invalid input', () => {
expect(() => validate(null)).toThrow('Input required');
});
// Snapshot testing (use sparingly)
it('renders correctly', () => {
const tree = renderer.create(<Component />).toJSON();
expect(tree).toMatchSnapshot();
});
// Table-driven tests
it.each([
[1, 1, 2],
[2, 2, 4],
[0, 0, 0],
])('add(%i, %i) = %i', (a, b, expected) => {
expect(add(a, b)).toBe(expected);
});**vitest.config.ts:**
export default defineConfig({
test: {
globals: true,
environment: 'node',
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
thresholds: {
lines: 80,
branches: 70,
functions: 80,
},
},
},
});pytest (Python)
import pytest
from mymodule import Calculator
# Fixtures for dependency injection
@pytest.fixture
def calculator():
return Calculator()
@pytest.fixture
def database():
db = TestDatabase()
yield db
db.cleanup()
# Parametrized tests
@pytest.mark.parametrize("a,b,expected", [
(1, 1, 2),
(2, 2, 4),
(0, 0, 0),
(-1, 1, 0),
])
def test_add(calculator, a, b, expected):
assert calculator.add(a, b) == expected
# Exception testing
def test_divide_by_zero(calculator):
with pytest.raises(ZeroDivisionError):
calculator.divide(1, 0)
# Async testing
@pytest.mark.asyncio
async def test_asyncRead more
name: comprehensive-testing description: Complete testing strategy covering TDD workflow, test pyramid, unit/integration/E2E/property testing, framework best practices (Jest, Vitest, pytest), mock strategies, and CI integration. Use when writing tests, reviewing test quality, or establishing testing standards. allowed-tools: Read, Grep, Glob, Bash, Edit, Write
Comprehensive Testing
> Based on [Anthropic's Claude Code Best Practices](https://www.anthropic.com/engineering/claude-code-best-practices) and community patterns
Core Philosophy
> "Claude performs best when it has a clear target to iterate against—a test case provides concrete success criteria."
Testing is not about proving code works; it's about **designing code that is testable** and **documenting expected behavior**.
---
Test Pyramid
/\
/ \ E2E Tests (10%)
/----\ - Full user flows
/ \ - Slowest, most brittle
/--------\
/ \ Integration Tests (20%)
/------------\ - Component interaction
/ \ - Real dependencies
/----------------\
Unit Tests (70%)
- Single function/method
- Fast, isolated, many| Level | Speed | Scope | When to Use | |-------|-------|-------|-------------| | Unit | <10ms | Single function | All logic | | Integration | <1s | Multiple components | APIs, DB | | E2E | <30s | Full flow | Critical paths |
---
TDD Workflow (Anthropic Recommended)
The 6-Step Process
1. WRITE TESTS FIRST ↓ 2. VERIFY TESTS FAIL ↓ 3. COMMIT TEST SUITE ↓ 4. IMPLEMENT CODE ↓ 5. VERIFY WITH SUBAGENT ↓ 6. COMMIT IMPLEMENTATION
Step 1: Write Tests First
Be EXPLICIT about TDD to avoid mock implementations: "I want to implement [feature] using TDD. First, write tests for [expected behavior] with these input/output pairs: - Input: X → Expected: Y - Input: A → Expected: B Do NOT create any implementation yet."
Step 2: Verify Tests Fail
# Run tests and confirm they fail for the RIGHT reason npm test # or pytest, go test, etc. # Expected: "function not found" or "undefined" # NOT: syntax error, wrong import
Step 3: Commit Test Suite
git add tests/ git commit -m "test: Add tests for [feature] (RED phase)"
Step 4: Implement Incrementally
"Now implement the code to make these tests pass. Do NOT modify the tests. Run tests after each change until all pass."
Claude will enter an autonomous loop:
Write code → Run tests → Analyze failures → Adjust → Repeat
Step 5: Verify with Subagent
"Use a subagent to independently verify the implementation: - Is it overfitting to tests? - Are edge cases handled? - Is the code maintainable?"
Step 6: Commit Implementation
git add src/ git commit -m "feat: Implement [feature] (GREEN phase)"
---
Test Structure Patterns
AAA Pattern (Arrange-Act-Assert)
describe('UserService', () => {
it('should create user with valid email', async () => {
// Arrange - Setup test data and dependencies
const userRepo = new InMemoryUserRepository();
const service = new UserService(userRepo);
const input = { email: 'test@example.com', name: 'Test' };
// Act - Execute the code under test
const user = await service.create(input);
// Assert - Verify the results
expect(user.email).toBe('test@example.com');
expect(user.id).toBeDefined();
expect(await userRepo.findById(user.id)).toEqual(user);
});
});Given-When-Then Pattern
def test_order_total_with_discount():
"""
Given an order with items totaling $100
When a 20% discount is applied
Then the total should be $80
"""
# Given
order = Order()
order.add_item(Item(price=50))
order.add_item(Item(price=50))
# When
order.apply_discount(Percentage(20))
# Then
assert order.total == Money(80)---
Framework Best Practices
Jest / Vitest (JavaScript/TypeScript)
// Structure
describe('ModuleName', () => {
describe('methodName', () => {
it('should [expected behavior] when [condition]', () => {});
});
});
// Setup/Teardown
beforeAll(async () => { /* one-time setup */ });
beforeEach(() => { /* per-test setup */ });
afterEach(() => { /* per-test cleanup */ });
afterAll(async () => { /* one-time cleanup */ });
// Async testing
it('handles async operations', async () => {
const result = await asyncFunction();
expect(result).toBe(expected);
});
// Error testing
it('throws on invalid input', () => {
expect(() => validate(null)).toThrow('Input required');
});
// Snapshot testing (use sparingly)
it('renders correctly', () => {
const tree = renderer.create(<Component />).toJSON();
expect(tree).toMatchSnapshot();
});
// Table-driven tests
it.each([
[1, 1, 2],
[2, 2, 4],
[0, 0, 0],
])('add(%i, %i) = %i', (a, b, expected) => {
expect(add(a, b)).toBe(expected);
});**vitest.config.ts:**
export default defineConfig({
test: {
globals: true,
environment: 'node',
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
thresholds: {
lines: 80,
branches: 70,
functions: 80,
},
},
},
});pytest (Python)
import pytest
from mymodule import Calculator
# Fixtures for dependency injection
@pytest.fixture
def calculator():
return Calculator()
@pytest.fixture
def database():
db = TestDatabase()
yield db
db.cleanup()
# Parametrized tests
@pytest.mark.parametrize("a,b,expected", [
(1, 1, 2),
(2, 2, 4),
(0, 0, 0),
(-1, 1, 0),
])
def test_add(calculator, a, b, expected):
assert calculator.add(a, b) == expected
# Exception testing
def test_divide_by_zero(calculator):
with pytest.raises(ZeroDivisionError):
calculator.divide(1, 0)
# Async testing
@pytest.mark.asyncio
async def test_asyncCross-runtime skills for Claude Code, Codex, and multi-agent workflows.
Repo: majiayu000/spellbook
Other skills on spellbook.
- /agentsmd-optimize
Audit AND optimize a CLAUDE.md / AGENTS.md instruction file — score it against the five high-leverage patterns, flag anti-patterns, then apply approved fixes in place. Use when the user says 优化 CLAUDE.md / 优化 AGENTS.md / optimize my agent doc / 帮我改 claudemd, or after an audit
Open skill - /agentsmd-scaffold
Generate or update repository-specific AGENTS.md instruction files from real repo evidence. Use when asked to create, design, scaffold, split, or improve root or scoped AGENTS.md files for Codex/Claude/agent workflows, especially when a repo needs directory-specific rules,
Open skill - /api-design
REST/GraphQL/gRPC API design best practices. Use when designing APIs, defining contracts, handling versioning. Covers OpenAPI 3.2, GraphQL Federation, gRPC streaming.
Open skill - /app-ui-design
Mobile app UI design expert for iOS and Android. Use when designing app interfaces, creating design systems, ensuring accessibility, or following platform guidelines. Covers Material Design 3, Human Interface Guidelines, color theory, typography, and 2025 trends.
Open skill - /app-user-story-qa
End-to-end app feature inventory and user-story testing workflow with a canonical tracker. Use when the user asks to audit every feature, derive expected behavior from code, test user journeys, or explicitly fix and retest documented UX or logistical defects.
Open skill - /architecture-foundation
Design architecture foundations before implementation. Use when asked to design or refactor architecture, choose Rust/Go crate, package, module, runtime, workflow, or service boundaries, compare mature project architecture, prevent stacked one-off PRs, audit migration debt in
Open skill

