Skip to main content
skill CX Codex

test-quality-analysis — Claude Code skill: what it does and setup

Spots overmocking, brittle selectors, and flaky tests in test suites. The skill guides test reviews and verifies coverage thresholds across codebases.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add secondsky/claude-skills --skill test-quality-analysis -a claude-code
Open on GitHub

What test-quality-analysis does

The skill equips the agent with guidelines to flag test smells and flawed assertions. It inspects unit and integration tests against FIRST principles and the Arrange-Act-Assert layout, pointing out race conditions or vague matchers.

Test coverage checks run through bun test --coverage targeting an 80% line threshold or uv run pytest --cov for Python projects. If a test mocks pure functions or sets up more than 3-4 mocks, the skill flags it as overmocked.

Only external I/O boundaries such as network APIs, databases, or disks should be mocked. The skill needs standard agent tool permissions including Bash, Read, and Grep to inspect code and run CLI test runners.

What it helps with

  • detect overmocking and mocked pure functions
  • eliminate flaky tests caused by bad async handling
  • replace brittle selectors with semantic locators
  • verify 80% line coverage and critical path tests

Example prompts for the agent

  • Review the unit tests in src/services/ for overmocking and vague assertions.
  • Run test coverage with Bun and report uncovered error paths.
  • Inspect this test file and fix the race condition causing it to flake.

How to install test-quality-analysis

1Skills CLI (Vercel)

npx skills add secondsky/claude-skills --skill test-quality-analysis -a claude-code

2Manually: put the files in place

~/.claude/skills/test-quality-analysis/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/test-quality-analysis/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about test-quality-analysis

How do I install test-quality-analysis in Claude Code?

Run npx skills add secondsky/claude-skills --skill test-quality-analysis -a claude-code. The file will be placed in ~/.claude/skills/test-quality-analysis/SKILL.md.

What does test-quality-analysis do?

It inspects test suites for testing anti-patterns, including testing implementation details instead of behavior. It also enforces clear assertions and checks coverage goals for critical paths.

When does the skill flag a test for overmocking?

Overmocking triggers when a test exceeds 3-4 mocks or substitutes pure utility functions instead of actual code. It permits mocks strictly for I/O boundaries like APIs and databases.

Source text

SKILL.md · MIT
---
name: test-quality-analysis
description: Detect test smells, overmocking, flaky tests, and coverage issues. Analyze test effectiveness, maintainability, and reliability. Use when reviewing tests or improving test quality.
allowed-tools: Bash, Read, Edit, Write, Grep, Glob, TodoWrite
license: MIT
---

# Test Quality Analysis

Expert knowledge for analyzing and improving test quality - detecting test smells, overmocking, insufficient coverage, and testing anti-patterns.

## Core Dimensions

- **Correctness**: Tests verify the right behavior
- **Reliability**: Tests are deterministic, not flaky
- **Maintainability**: Tests are easy to understand
- **Performance**: Tests run quickly
- **Coverage**: Tests cover critical code paths
- **Isolation**: Tests don't depend on external state

## Test Smells

### Overmocking

**Problem**: Mocking too many dependencies makes tests fragile.

```typescript
// ❌ BAD: Overmocked
test('calculate total', () => {
  const mockAdd = vi.fn(() => 10)
  const mockMultiply = vi.fn(() => 20)
  // Testing implementation, not behavior
})

// ✅ GOOD: Mock only external dependencies
test('calculate order total', () => {
  const mockPricingAPI = vi.fn(() => ({ tax: 0.1 }))
  const total = calculateTotal(order, mockPricingAPI)
  expect(total).toBe(38)
})
```

**Detection**: More than 3-4 mocks, mocking pure functions, complex mock setup.

**Fix**: Mock only I/O boundaries (APIs, databases, filesystem).

### Fragile Tests

**Problem**: Tests break with unrelated code changes.

```typescript
// ❌ BAD: Tests implementation details
await page.locator('.form-container > div:nth-child(2) > button').click()

// ✅ GOOD: Semantic selector
await page.getByRole('button', { name: 'Submit' }).click()
```

### Flaky Tests

**Problem**: Tests pass or fail non-deterministically.

```typescript
// ❌ BAD: Race condition
test('loads data', async () => {
  fetchData()
  await new Promise(resolve => setTimeout(resolve, 1000))
  expect(data).toBeDefined()
})

// ✅ GOOD: Proper async handling
test('loads data', async () => {
  const data = await fetchData()
  expect(data).toBeDefined()
})
```

### Poor Assertions

```typescript
// ❌ BAD: Weak assertion
test('returns users', async () => {
  const users = await getUsers()
  expect(users).toBeDefined() // Too vague!
})

// ✅ GOOD: Strong, specific assertions
test('creates user with correct attributes', async () => {
  const user = await createUser({ name: 'John' })
  expect(user).toMatchObject({
    id: expect.any(Number),
    name: 'John',
  })
})
```

## Analysis Tools

```bash
# Vitest coverage (prefer bun)
bun test --coverage
open coverage/index.html

# Check thresholds
bun test --coverage --coverage.thresholds.lines=80

# pytest-cov (Python)
uv run pytest --cov --cov-report=html
open htmlcov/index.html
```

## Best Practices Checklist

### Unit Test Quality (FIRST)
- [ ] **Fast**: Tests run in milliseconds
- [ ] **Isolated**: No dependencies between tests
- [ ] **Repeatable**: Same results every time
- [ ] **Self-validating**: Clear pass/fail
- [ ] **Timely**: Written alongside code

### Mock Guidelines
- [ ] Mock only external dependencies
- [ ] Don't mock business logic or pure functions
- [ ] Use real implementations when possible
- [ ] Limit to 3-4 mocks per test maximum

### Coverage Goals
- [ ] 80%+ line coverage for business logic
- [ ] 100% for critical paths (auth, payment)
- [ ] All error paths tested
- [ ] Boundary conditions tested

### Test Structure (AAA Pattern)

```typescript
test('user registration', async () => {
  // Arrange
  const userData = { email: '[email protected]' }

  // Act
  const user = await registerUser(userData)

  // Assert
  expect(user.email).toBe('[email protected]')
})
```

## Code Review Checklist

- [ ] Tests verify behavior, not implementation
- [ ] Assertions are specific and meaningful
- [ ] No flaky tests (timing, ordering issues)
- [ ] Proper async/await usage
- [ ] Test names clearly describe behavior
- [ ] Minimal code duplication
- [ ] Critical paths have tests
- [ ] Both happy path and error cases covered

## Common Anti-Patterns

### Testing Implementation Details

```typescript
// ❌ BAD
const spy = vi.spyOn(Math, 'sqrt')
calculateDistance()
expect(spy).toHaveBeenCalled() // Testing how, not what

// ✅ GOOD
const distance = calculateDistance({ x: 0, y: 0 }, { x: 3, y: 4 })
expect(distance).toBe(5) // Testing output
```

### Mocking Too Much

```typescript
// ❌ BAD
const mockAdd = vi.fn((a, b) => a + b)

// ✅ GOOD: Use real implementations
import { add } from './utils'
// Only mock external services
const mockPaymentGateway = vi.fn()
```

## See Also

- `vitest-testing` - TypeScript/JavaScript testing
- `playwright-testing` - E2E testing
- `mutation-testing` - Validate test effectiveness

© secondsky · MIT · secondsky/claude-skills

Similar skills

All skills for Testing and QA →

From the same set116

payment-gateway-integration A skill for wiring Stripe, PayPal or Square into your app: payment intents, subscriptions, webhooks and refunds. Useful when you build checkout or billing. CX Codex +1 454installs api-reference-documentation Turns an OpenAPI spec into a developer-facing API reference: endpoints, auth, request and response examples. Useful for SDK docs and developer portals. CX Codex +1 454installs csrf-protection A skill that walks your agent through CSRF protection: synchronizer tokens, double-submit cookies and SameSite attributes. CX Codex +1 453installs bun-hono-integration A skill that tells the agent how to build Hono APIs on Bun: routes, middleware, Zod validation, RPC client. Useful when your project already runs on Bun. CX Codex +1 452installs tanstack-router Configures type-safe file-based routing in React SPAs and resolves integration issues with TanStack Query or Cloudflare Workers. CX Codex +1 445installs interaction-design A skill for designing interface feedback: loading states, errors, empty screens, animation timing and accessibility. Useful when you need to plan how UI behaves, not just how it looks. CX Codex +1 441installs bun-package-manager Bun package manager reference for commands, monorepos, and pnpm migrations. It guides agents on installation flags and lockfile conversions. CX Codex +1 440installs api-error-handling The skill sets a standard error response shape, an ApiError class and a circuit breaker. Useful once your API hits production. CX Codex +1 440installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor