test-levels
This skill explains the 3 test levels (Unit, Integration, E2E) using the "Building a Car" analogy and provides guidance on when to use each type. Includes project-specific Playwright examples.
Best use case
test-levels is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
This skill explains the 3 test levels (Unit, Integration, E2E) using the "Building a Car" analogy and provides guidance on when to use each type. Includes project-specific Playwright examples.
Teams using test-levels should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/test-levels/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How test-levels Compares
| Feature / Agent | test-levels | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
This skill explains the 3 test levels (Unit, Integration, E2E) using the "Building a Car" analogy and provides guidance on when to use each type. Includes project-specific Playwright examples.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Test Levels Guide
Explains test types & guides test selection using car analogy.
## When to Use
Invoke when:
- Explaining test concepts to team members
- Deciding which test type to write
- Reviewing test coverage strategy
- Onboarding new developers to testing
## The 3 Test Levels
### 1. Unit Test (Test Case)
**The specific instruction.**
Single fn/component tested in isolation. No external deps (DB, API, browser).
| Aspect | Description |
|--------|-------------|
| Analogy | "Check if left turn signal blinks when I push lever down" |
| Scope | Tiny detail - one fn, one input/output |
| Speed | Fast (ms) |
| Location | `tests/unit/` |
**When to write:**
- Pure functions (formatters, validators, utils)
- Data transformations
- Business logic w/o side effects
**Project example:**
```typescript
// tests/unit/utils/formatters.spec.ts
import {expect, test} from 'next/experimental/testmode/playwright';
import {leadingZero, formatCurrency} from '@/app/_utils/formatters';
test.describe('formatters', () => {
test('leadingZero adds zero to single-digit numbers', () => {
expect(leadingZero(7)).toBe('07');
expect(leadingZero(10)).toBe('10');
});
test('formatCurrency formats correctly', () => {
const result = formatCurrency({value: 1234.56, locale: 'en', currency: 'USD'});
expect(result).toBe('1,234.56 $');
});
});
```
---
### 2. Integration Test
**The handshake.**
Tests if 2+ parts communicate correctly. Focuses on connections, not full system.
| Aspect | Description |
|--------|-------------|
| Analogy | "Does engine make wheels turn?" (Engine → Transmission) |
| Scope | Connections between components |
| Speed | Medium (100ms-few seconds) |
| Location | `tests/integration/` |
**When to write:**
- Validators w/ schemas (Zod)
- API route handlers
- Service-to-service communication
- DB queries w/ mocked data
**Project example:**
```typescript
// tests/integration/validators/offer.spec.ts
import {expect, test} from 'next/experimental/testmode/playwright';
import {mockLoggedUser} from '../../common';
import {validateCustomerStatus} from '@/app/_lib/validator';
test.beforeEach(async ({context}) => {
await mockLoggedUser(context);
});
test.describe('validate customer status', () => {
const validData = {
offerId: '670e80f0a65da593d265088a',
status: 'viewing',
};
test('returns success for valid data', async () => {
const result = validateCustomerStatus(validData);
expect(result.success).toBe(true);
expect(result.data).toEqual(validData);
});
test('returns error for invalid offerId', async () => {
const result = validateCustomerStatus({...validData, offerId: ''});
expect(result.success).toBe(false);
expect(result.error?.issues[0]?.path).toContain('offerId');
});
});
```
---
### 3. E2E Test (End-to-End)
**The real user journey.**
Full system test: browser, DB, network, 3rd-party services. Exactly as user experiences.
| Aspect | Description |
|--------|-------------|
| Analogy | "Start car, drive to store, park, turn off" |
| Scope | Full user flow |
| Speed | Slow (seconds-minutes) |
| Location | `tests/pages/` |
**When to write:**
- Critical user flows (login, checkout, payment)
- Multi-page journeys
- Features requiring browser interaction
- Smoke tests for deployment
**Project example:**
```typescript
// tests/pages/start.spec.ts
import {expect, test} from 'next/experimental/testmode/playwright';
import {mockLoggedUser, resetAPIEndpointsMock} from '../common';
test.beforeEach(async ({context}) => {
await mockLoggedUser(context);
});
test.afterEach(async ({next, context}) => {
await resetAPIEndpointsMock(next);
await context.clearCookies();
});
test('start page renders correctly', async ({page}) => {
test.setTimeout(120000);
await page.goto('http://localhost:3000/start', {
timeout: 90000,
waitUntil: 'domcontentloaded'
});
await expect(page).toHaveURL('http://localhost:3000/start');
await expect(page.getByTestId('pageHeader')).toHaveClass('drop-shadow-font');
await expect(page.getByTestId('subTotal')).toContainText('Sub total');
await expect(page.getByTestId('startCounter')).toContainText('Your vacation starts in');
});
```
---
## Quick Decision Guide
| Question | Test Type |
|----------|-----------|
| "Does this fn return correct value?" | Unit |
| "Do these 2 parts work together?" | Integration |
| "Does full flow work for user?" | E2E |
### Test Pyramid
```
/\
/E2E\ Few (slow, expensive)
/------\
/Integr- \ Some (medium)
/ ation \
/------------\
/ Unit \ Many (fast, cheap)
/________________\
```
**Rule:** More unit tests, fewer E2E tests. Unit tests catch bugs early & run fast.
---
## Project Structure
```
tests/
├── unit/ # Pure fn tests (no browser)
│ └── utils/ # Utility fn tests
├── integration/ # Component interaction tests
│ ├── validators/ # Schema validation tests
│ └── lib/ # Library fn tests
├── pages/ # E2E browser tests
│ ├── start.spec.ts
│ ├── payment.spec.ts
│ └── confirm.spec.ts
├── common.ts # Shared test utilities
├── mock/ # Mock data & helpers
└── seed.spec.ts # DB seed for tests
```
---
## Commands
```bash
# Run all tests (headed mode)
npm run test
# Run specific test file
npm run test tests/unit/utils/formatters.spec.ts
# Run tests in UI mode
npm run test:ui
# Show test report
npm run test:report
```
---
## Best Practices
1. **Name tests clearly:** `should [action] when [condition]`
2. **One assertion focus:** Test one behavior per test
3. **Use test.describe:** Group related tests
4. **Clean up:** Use `afterEach` for state reset
5. **Mock external deps:** Use `mockLoggedUser`, `resetAPIEndpointsMock`
6. **Set timeouts:** E2E tests need longer timeouts (120s)
7. **Use data-testid:** For reliable element selection
---
## Summary Table
| Level | Question | Scope | Speed | Location |
|-------|----------|-------|-------|----------|
| **Unit** | "Does this fn work?" | Single fn | Fast | `tests/unit/` |
| **Integration** | "Do parts connect?" | Connections | Medium | `tests/integration/` |
| **E2E** | "Does flow work?" | Full system | Slow | `tests/pages/` |Related Skills
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
testing-automation-expert
Production-grade testing strategies for robust, maintainable systems. Covers unit/integration/E2E testing, contract testing, accessibility, mutation testing, and CI/CD patterns. Supports Python (pytest) and TypeScript (Jest/Vitest/Playwright).
web-quality
Web quality optimization skills based on Google Lighthouse guidelines and Core Web Vitals. Use when asked to audit web quality, optimize performance, improve accessibility, fix SEO, apply best practices, or analyze Core Web Vitals (LCP, INP, CLS).
vercel-react-native-skills
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
upgrade-packages-js
Safely upgrade JavaScript packages with breaking change detection, migration guidance, and automated code migrations (npm/pnpm/yarn). Cross-platform with git safety branch enforcement.
uiux-toolkit
Comprehensive UX/UI evaluation meta-skill combining design theory and UX methodology. Use when conducting UI/UX audits, visual design reviews, accessibility compliance (WCAG 2.2), user flow analysis, responsive testing, interaction design evaluation, or design system audits. Evaluates using Nielsen's heuristics, Gestalt principles, typography theory, color theory, and modern methodologies (OOUX, JTBD, Cognitive Walkthrough).
ui-ux-pro-max
UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 9 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind, shadcn/ui). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient. Integrations: shadcn/ui MCP for component search and examples.
trailofbits-security
Security-focused static analysis and code auditing skills from Trail of Bits. Includes CodeQL deep analysis, Semgrep scanning, and SARIF result processing. Use when performing security audits, running static analysis, scanning for vulnerabilities, or processing scan results.
token-optimizer
Reduce token count in prompts, docs, and prose. Covers prompt compression (40-60% savings), doc formatting, TOON data serialization, and Strunk's prose clarity rules. Use when compressing prompts, optimizing docs for LLM context, or writing clear technical prose.
terraform
Terraform infrastructure-as-code skills from HashiCorp. Covers HCL code generation with style conventions, testing with .tftest.hcl files, and module refactoring. Use when writing, reviewing, generating, or refactoring Terraform configurations, creating tests, or designing modules.
system-architect
System architecture skill for designing scalable, maintainable software systems. Covers microservices/monolith decisions, API design, DB selection, caching, security, and scalability planning.
swiftui-patterns
SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.