Writing effective tests and running them successfully. Covers layer-specific mocking rules, test design principles, debugging failures, and flaky test management. Use when writing tests, reviewing test quality, or debugging test failures.
/plugin marketplace add rsmdt/the-startup/plugin install team@the-startupThis skill inherits all available tools. When active, it can use any tool Claude has access to.
examples/test-pyramid.mdHow to write effective tests and run them successfully.
Purpose: Verify isolated business logic.
Mocking rules:
// CORRECT: Mock only external dependency
const service = new OrderService(mockRepository) // Repository is the edge
const total = service.calculateTotal(order)
expect(total).toBe(90)
// WRONG: Mocking internal methods
vi.spyOn(service, 'applyDiscount') // Now you're testing the mock
Characteristics: < 100ms, no I/O, deterministic
Test here: Business logic, validation, transformations, edge cases
Purpose: Verify components work together with real dependencies.
Mocking rules:
// CORRECT: Real DB, mock external payment API
const db = await createTestDatabase()
const paymentApi = vi.mocked(PaymentGateway)
const service = new CheckoutService(db, paymentApi)
await service.checkout(cart)
expect(await db.orders.find(orderId)).toBeDefined() // Real DB
expect(paymentApi.charge).toHaveBeenCalledOnce() // Mocked external
Characteristics: < 5 seconds, containerized deps, clean state between tests
Test here: Database queries, API contracts, service communication, caching
Purpose: Validate critical user journeys in the real system.
Mocking rules:
// Real browser, real system (Playwright example)
await page.goto('/checkout')
await page.fill('#card', '4242424242424242')
await page.click('[data-testid="pay"]')
await expect(page.locator('.confirmation')).toContainText('Order confirmed')
Characteristics: < 30 seconds, critical paths only, fix flakiness immediately
Test here: Signup, checkout, auth flows, smoke tests
// CORRECT: Observable behavior
expect(order.total).toBe(108)
// WRONG: Implementation detail
expect(order._calculateTax).toHaveBeenCalled()
// Arrange
const mockEmail = vi.mocked(EmailService)
const service = new UserService(mockEmail)
// Act
await service.register(userData)
// Assert
expect(mockEmail.sendTo).toHaveBeenCalledWith('user@example.com')
Multiple assertions OK if verifying same logical outcome.
// GOOD
it('rejects order when inventory insufficient', ...)
// BAD
it('test order', ...)
No shared mutable state between tests.
Unit test fails:
Integration test fails:
E2E test fails:
Handle aggressively - they erode trust:
Quality over quantity - 80% meaningful coverage beats 100% trivial coverage.
Focus testing effort on business-critical paths (payments, auth, core domain logic). Skip generated code.
Always test:
Boundaries: min-1, min, min+1, max-1, max, max+1, zero, one, many
Special values: null, empty, negative, MAX_INT, NaN, unicode, leap years, timezones
Errors: Network failures, timeouts, invalid input, unauthorized
| Pattern | Problem |
|---|---|
| Over-mocking | Testing mocks instead of code |
| Implementation testing | Breaks on refactoring |
| Shared state | Test order affects results |
| Test duplication | Use parameterized tests instead |
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.