testing-strategy
Testing Strategy Guide
Testing Pyramid
/\
/ \ E2E (Few)
/----\
/ \ Integration (Some)
/--------\
/ \ Unit (Many)
/______________\
Test Types
Unit Tests
- What: Single function/component in isolation
- Speed: Fast (ms)
- When: Business logic, utilities, pure functions
- Tools: Jest, Vitest, pytest
Integration Tests
- What: Multiple units working together
- Speed: Medium (seconds)
- When: API endpoints, database operations, component + hooks
- Tools: Supertest, Testing Library, pytest
End-to-End Tests
- What: Full user flows
- Speed: Slow (10+ seconds)
- When: Critical paths, smoke tests
- Tools: Playwright, Cypress, Detox
What to Test
Always Test
- Business logic
- Edge cases (empty, null, boundary values)
- Error handling paths
- User-facing critical paths
- Security-sensitive operations
Skip Testing
- Third-party library internals
- Trivial getters/setters
- Framework boilerplate
- Implementation details
Test Structure (AAA Pattern)
test('should calculate total with discount', () => {
// Arrange - Set up test data
const items = [{ price: 100 }, { price: 50 }];
const discount = 0.1;
// Act - Execute the code
const total = calculateTotal(items, discount);
// Assert - Verify the result
expect(total).toBe(135);
});
Naming Conventions
Pattern: should [expected behavior] when [condition]
Good:
should return empty array when no items matchshould throw error when user is not authenticatedshould redirect to login when session expires
Bad:
test1works correctlycalculateTotal
Mocking Guidelines
When to Mock
- External services (APIs, databases)
- Time-dependent operations
- Random number generation
- File system operations
When NOT to Mock
- The code under test
- Simple utilities
- When integration testing
Mock Patterns
// Partial mock
jest.mock('./api', () => ({
...jest.requireActual('./api'),
fetchUser: jest.fn()
}));
// Reset between tests
beforeEach(() => {
jest.clearAllMocks();
});
React Testing
Component Testing Library Pattern
// Test behavior, not implementation
test('displays error when form is invalid', async () => {
render(<SignupForm />);
await userEvent.click(screen.getByRole('button', { name: /submit/i }));
expect(screen.getByRole('alert')).toHaveTextContent(/email required/i);
});
What to Query
getByRole > getByLabelText > getByPlaceholderText > getByText > getByTestId
Coverage Guidelines
| Type | Target | Note |
|---|---|---|
| Line | 80% | Minimum for CI gate |
| Branch | 70% | More important than line |
| Function | 90% | Ensure all exports tested |
100% coverage is not a goal - diminishing returns after ~85%
Flaky Test Solutions
| Cause | Fix |
|---|---|
| Timing issues | Proper async/await, waitFor |
| Shared state | Reset in beforeEach |
| External dependencies | Mock them |
| Race conditions | Explicit ordering |
| Date/time | Mock Date.now() |
Test Organization
src/
components/
Button/
Button.tsx
Button.test.tsx # Co-located
utils/
format.ts
format.test.ts
tests/
integration/ # Cross-module tests
e2e/ # User flow tests
CI/CD Integration
# Run fast tests first
test:unit → test:integration → test:e2e
- Unit tests: Every commit
- Integration: Every PR
- E2E: Before deploy, nightly
More from jamelna-apps/claude-dash
cost-tracking
When user mentions "spending", "usage", "tokens", "API cost", "budget", "expensive", or wants to understand Claude API costs. Provides cost awareness and optimization guidance.
11page-cro
When the user mentions "conversion", "CRO", "landing page", "not converting", "bounce rate", "optimize page", or asks about improving page performance.
7session-handoff
When user says "continue", "pick up where we left off", "last time", "previous session", "what were we doing", or wants explicit session continuity. Provides structured context handoff between sessions.
4code-review
When the user mentions "review", "PR", "pull request", "code review", "check my code", "feedback on", or asks for code quality assessment.
3git-workflow
When user mentions "commit", "branch", "merge", "git history", "what changed", "since last session", "PR", or needs git context. Provides session continuity via git awareness.
3mode-awareness
When explicitly switching modes or when mode detection shows low confidence. Provides guidance on optimal approach for each detected mode (debugging, performance, feature, refactor, exploration, infrastructure).
3