daffy0208/ai-dev-standards/testing-strategist

Claude Code and agent skill by daffy0208/ai-dev-standards

Trust tier 2
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Design and implement comprehensive testing strategies. Use when setting up tests, choosing test types, implementing TDD, or improving code quality. Covers unit tests, integration tests, E2E tests, test-driven development, and testing best practices.

Install

npx vskill@latest install daffy0208/ai-dev-standards/testing-strategist

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

Testing Strategist

Test the right things at the right level - write tests that give you confidence to ship.

Core Principle

The Testing Pyramid: 70% unit tests, 20% integration tests, 10% E2E tests.

Tests should be:

  • Fast - Run in milliseconds (unit) to seconds (integration) to minutes (E2E)
  • Isolated - Test one thing at a time
  • Repeatable - Same input = same output
  • Self-checking - Pass/fail automatically, no manual verification
  • Timely - Written alongside code (or before, with TDD)

The Testing Pyramid

/\
/ \ E2E Tests (10%)
/----\ - Slow, brittle, expensive
/ \ - Test critical user journeys
/--------\ - Example: "User can complete checkout"
/ \
/------------\ Integration Tests (20%)
/ \ - Medium speed, test components together
/----------------\ - Example: "API endpoint returns correct data"
/ \
/--------------------\ Unit Tests (70%)
/______________________\ - Fast, isolated, test functions/components
- Example: "calculateTotal returns sum"
Why This Ratio?
  • Unit tests: Fast feedback, pinpoint bugs precisely, easy to maintain
  • Integration tests: Ensure components work together, catch interface issues
  • E2E tests: Verify actual user flows, catch UI bugs, but slow and brittle

Level 1: Unit Tests (70%)

What to Test

Test individual functions, components, or classes in isolation.

Good candidates:

  • ✅ Business logic functions (calculations, validation, transformations)
  • ✅ Utility functions (formatDate, parseUrl, etc.)
  • ✅ React components (rendering, props, state)
  • ✅ Hooks (custom React hooks)
  • ✅ Pure functions (same input = same output)

Skip:

  • ❌ Third-party libraries (assume they work)
  • ❌ Framework internals (React, Next.js)
  • ❌ Simple getters/setters with no logic
Unit Test Examples
Testing Business Logic (Jest + TypeScript)
typescript
// src/lib/pricing.ts
export function calculateTotal(items: { price: number; quantity: number }[]) {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0)
}
export function applyDiscount(total: number, discountPercent: number) {
if (discountPercent < 0 || discountPercent > 100) {
throw new Error('Invalid discount percentage')
}
return total * (1 - discountPercent / 100)
}
// src/lib/pricing.test.ts
import { calculateTotal, applyDiscount } from './pricing'
describe('calculateTotal', () => {
it('calculates total for single item', () => {
const items = [{ price: 10, quantity: 2 }]
expect(calculateTotal(items)).toBe(20)
})
it('calculates total for multiple items', () => {
const items = [
{ price: 10, quantity: 2 },
{ price: 5, quantity: 3 }
]
expect(calculateTotal(items)).toBe(35)
})
it('returns 0 for empty array', () => {
expect(calculateTotal([])).toBe(0)
})
})
describe('applyDiscount', () => {
it('applies discount correctly', () => {
expect(applyDiscount(100, 20)).toBe(80)
})
it('throws error for invalid discount', () => {
expect(() => applyDiscount(100, -10)).toThrow('Invalid discount')
expect(() => applyDiscount(100, 150)).toThrow('Invalid discount')
})
})
Testing React Components (Jest + React Testing Library)
typescript
// src/components/Button.tsx
export function Button({
children,
variant = 'primary',
onClick
}: {
children: React.ReactNode
variant?: 'primary' | 'secondary'
onClick?: () => void
}) {
return (
<button
className={`btn btn-${variant}`}
onClick={onClick}
>
{children}
</button>
)
}
// src/components/Button.test.tsx
import { render, screen, fireEvent } from '@testing-library/react'
import { Button } from './Button'
describe('Button', () => {
it('renders with correct text', () => {
render(<Button>Click me</Button>)
expect(screen.getByText('Click me')).toBeInTheDocument()
})
it('applies primary variant by default', () => {
render(<Button>Click me</Button>)
expect(screen.getByRole('button')).toHaveClass('btn-primary')
})
it('applies secondary variant when specified', () => {
render(<Button variant="secondary">Click me</Button>)
expect(screen.getByRole('button')).toHaveClass('btn-secondary')
})
it('calls onClick when clicked', () => {
const handleClick = jest.fn()
render(<Button onClick={handleClick}>Click me</Button>)
fireEvent.click(screen.getByRole('button'))
expect(handleClick).toHaveBeenCalledTimes(1)
})
})
Testing Custom Hooks
typescript
// src/hooks/useCounter.ts
import { useState } from 'react'
export function useCounter(initialValue = 0) {
const [count, setCount] = useState(initialValue)
const increment = () => setCount(c => c + 1)
const decrement = () => setCount(c => c - 1)
const reset = () => setCount(initialValue)
return { count, increment, decrement, reset }
}
// src/hooks/useCounter.test.ts
import { renderHook, act } from '@testing-library/react'
import { useCounter } from './useCounter'
describe('useCounter', () => {
it('initializes with default value', () => {
const { result } = renderHook(() => useCounter())
expect(result.current.count).toBe(0)
})
it('initializes with custom value', () => {
const { result } = renderHook(() => useCounter(10))
expect(result.current.count).toBe(10)
})
it('increments count', () => {
const { result } = renderHook(() => useCounter())
act(() => {
result.current.increment()
})
expect(result.current.count).toBe(1)
})
it('decrements count', () => {
const { result } = renderHook(() => useCounter(5))
act(() => {
result.current.decrement()
})
expect(result.current.count).toBe(4)
})
it('resets to initial value', () => {
const { result } = renderHook(() => useCounter(10))
act(() => {
result.current.increment()
result.current.increment()
result.current.reset()
})
expect(result.current.count).toBe(10)
})
})
Unit Test Best Practices

✅ Do:

  • Test behavior, not implementation
  • Use descriptive test names (it should...)
  • Follow AAA pattern: Arrange, Act, Assert
  • Test edge cases (empty arrays, null, negative numbers)
  • Keep tests simple and readable

❌ Don't:

  • Test private methods directly
  • Over-mock (makes tests brittle)
  • Test framework internals
  • Write tests that depend on other tests

Level 2: Integration Tests (20%)

What to Test

Test multiple units working together - typically API routes, database operations, or service integrations.

Good candidates:

  • ✅ API endpoints (request → controller → database → response)
  • ✅ Database operations (queries, transactions)
  • ✅ Third-party integrations (Stripe, SendGrid)
  • ✅ Authentication flows
  • ✅ File upload/download
Integration Test Examples
Testing API Routes (Next.js + Supertest)
typescript
// app/api/posts/route.ts
export async function GET() {
const posts = await db.post.findMany({
include: { author: true },
orderBy: { createdAt: 'desc' }
})
return Response.json(posts)
}
export async function POST(request: Request) {
const body = await request.json()
// Validate
const result = PostSchema.safeParse(body)
if (!result.success) {
return Response.json({ errors: result.error.issues }, { status: 400 })
}
// Create post
const post = await db.post.create({
data: {
title: result.data.title,
content: result.data.content,
authorId: request.user.id
}
})
return Response.json(post, { status: 201 })
}
// app/api/posts/route.test.ts
import { testClient } from '@/lib/test-utils'
describe('POST /api/posts', () => {
beforeEach(async () => {
// Clean database before each test
await db.post.deleteMany()
})
it('creates a new post', async () => {
const response = await testClient
.post('/api/posts')
.set('Authorization', `Bearer ${authToken}`)
.send({
title: 'Test Post',
content: 'This is a test post'
})
expect(response.status).toBe(201)
expect(response.body).toMatchObject({
title: 'Test Post',
content: 'This is a test post'
})
// Verify in database
const posts = await db.post.findMany()
expect(posts).toHaveLength(1)
expect(posts[0].title).toBe('Test Post')
})
it('returns 400 for invalid data', async () => {
const response = await testClient
.post('/api/posts')
.set('Authorization', `Bearer ${authToken}`)
.send({
title: '' // Invalid: empty title
})
expect(response.status).toBe(400)
expect(response.body.errors).toBeDefined()
})
it('returns 401 for unauthenticated request', async () => {
const response = await testClient.post('/api/posts').send({
title: 'Test',
content: 'Test'
})
expect(response.status).toBe(401)
})
})
describe('GET /api/posts', () => {
beforeEach(async () => {
await db.post.deleteMany()
// Seed test data
await db.post.createMany({
data: [
{ title: 'Post 1', content: 'Content 1', authorId: user.id },
{ title: 'Post 2', content: 'Content 2', authorId: user.id }
]
})
})
it('returns all posts', async () => {
const response = await testClient.get('/api/posts')
expect(response.status).toBe(200)
expect(response.body).toHaveLength(2)
expect(response.body[0].author).toBeDefined()
})
})
Testing Database Operations
typescript
// src/lib/repositories/userRepository.test.ts
import { db } from '@/lib/db'
import { createUser, findUserByEmail, updateUser } from './userRepository'
describe('userRepository', () => {
beforeEach(async () => {
await db.user.deleteMany()
})
afterAll(async () => {
await db.$disconnect()
})
describe('createUser', () => {
it('creates user with hashed password', async () => {
const user = await createUser({
email: 'test@example.com',
password: 'password123'
})
expect(user.email).toBe('test@example.com')
expect(user.password).not.toBe('password123') // Should be hashed
expect(user.password).toMatch(/^\$2[aby]/) // bcrypt hash format
})
it('throws error for duplicate email', async () => {
await createUser({ email: 'test@example.com', password: 'pass' })
await expect(createUser({ email: 'test@example.com', password: 'pass' })).rejects.toThrow()
})
})
describe('findUserByEmail', () => {
it('finds existing user', async () => {
await createUser({ email: 'test@example.com', password: 'pass' })
const user = await findUserByEmail('test@example.com')
expect(user).toBeDefined()
expect(user?.email).toBe('test@example.com')
})
it('returns null for non-existent user', async () => {
const user = await findUserByEmail('nonexistent@example.com')
expect(user).toBeNull()
})
})
})
Integration Test Best Practices

✅ Do:

  • Use test database (separate from development/production)
  • Clean up test data (beforeEach/afterEach)
  • Test happy path + error cases
  • Test authentication/authorization
  • Use factories/fixtures for test data

❌ Don't:

  • Test against production database
  • Leave test data behind
  • Mock database (defeats purpose of integration test)
  • Depend on external services (mock external APIs)

Level 3: E2E Tests (10%)

What to Test

Test complete user journeys through the actual UI.

Good candidates:

  • ✅ Critical user flows (signup, login, checkout)
  • ✅ Core business processes
  • ✅ Multi-step workflows

Skip:

  • ❌ Every possible UI interaction (too slow/brittle)
  • ❌ Edge cases (cover with unit/integration tests)
E2E Test Examples (Playwright)

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 96 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
21
Repository forks
6
7-day trend score
15

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 16 Mar 2026, 8 months ago.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/daffy0208/ai-dev-standards/testing-strategist/badge)](https://verified-skill.com/skills/daffy0208/ai-dev-standards/testing-strategist)

Something wrong with this skill or its page? Tell us.