Skip to content

Run a Test Code Quality Checklist with AI

Test Code ReviewUpdated 2026-10-21basic
TL;DR

Returns a per-test-file quality checklist with 20-30 items grouped by category (naming / structure / assertions / isolation / performance / maintainability): each marked PASS/FAIL with one-line evidence from the code.

When to use it

  • Pre-merge sanity check on new test files.
  • Auditing an existing test file before refactor.
  • Standardizing quality across a team.
  • Teaching engineers what 'good test code' looks like by showing what to check.

The prompt

XML-tagged: works best with Claude
test-code-quality-checklist.claude.mdprompt
<role>You are a test quality coach. You evaluate test files against a structured rubric so reviewers can see EXACTLY where the file falls short.</role> <context>Categories (every test file should cover):- **Naming**: describe / it / test names; constants vs magic; clarity- **Structure**: Arrange-Act-Assert; setup/teardown; describe blocks- **Assertions**: strong vs weak; one concept per test; failure messages- **Isolation**: independence between tests; shared state; test order- **Performance**: no hard sleeps; parallelizable; reasonable runtime per test- **Maintainability**: readability; DRY (not over-DRY); future-proof selectors</context> <task>For the test file below, run a checklist with 20-30 items spread across the 6 categories. Each item:1. Concrete check (e.g., "All `test()` names are imperative sentences describing behavior")2. PASS / FAIL marker3. Evidence (line number or snippet) supporting the verdict4. If FAIL, what would make it pass Group items by category. Items must be specific to the file's framework (Playwright / Jest / etc.).</task> <input>Test file content: {test_code}Framework: {framework}</input> <constraints>- 20-30 items total, distributed roughly equally across the 6 categories.- Each item is YES/NO answerable; no gradient.- Evidence is required for both PASS and FAIL.- Distinguish framework idioms (Jest `toBe` vs Playwright `toEqual`).- Don't double-count: one underlying issue shouldn't fail 3 checklist items.</constraints> <output_format>Markdown sections per category (6 H2 headings). Each section contains a table: Check | Status | Evidence | If FAIL, fix by. End with an overall "Score" (count of PASS / total).</output_format> <approach>Before writing, identify which items are MOST RELEVANT to this file's particular shape: don't pad the checklist with irrelevancies.</approach>

Example

Input
Test file content:
```typescript
1   import { test, expect } from '@playwright/test';
2   import { LoginPage } from './pages/LoginPage';
3
4   test.describe('Login flow', () => {
5     let loginPage: LoginPage;
6
7     test.beforeEach(async ({ page }) => {
8       loginPage = new LoginPage(page);
9       await loginPage.goto();
10    });
11
12    test('signs in with valid credentials and redirects to dashboard', async ({ page }) => {
13      await loginPage.signIn('alice@example.com', 'Password123');
14      await expect(page).toHaveURL(/\/dashboard/);
15      await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
16    });
17
18    test('shows error for invalid password', async () => {
19      await loginPage.signIn('alice@example.com', 'wrong');
20      await loginPage.assertErrorVisible('Invalid credentials');
21    });
22
23    test('navigates to forgot password page', async ({ page }) => {
24      await loginPage.openForgotPassword();
25      await expect(page).toHaveURL(/\/forgot-password/);
26    });
27  });
```

Framework: Playwright
Output
## 1. Naming

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| Describe block name is descriptive | PASS | Line 4: `Login flow` | - |
| Test names use imperative form describing behavior | PASS | Lines 12, 18, 23: "signs in", "shows error", "navigates" | - |
| Test names avoid implementation details | PASS | No mention of selectors or button clicks in names | - |
| File path conveys feature context | PASS (unverified) | Filename not given; the describe name suggests `tests/login/...`. Confirm before relying on this | If filename is generic (`tests1.spec.ts`), rename to feature-scoped |
| No magic strings in test bodies | PASS (see Maintainability) | Lines 13, 19 hold inline credentials; counted once, under "Test data externalized", to avoid double-counting | - |

## 2. Structure

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| Uses `describe` to group related tests | PASS | Line 4 | - |
| Uses `beforeEach` for shared setup | PASS | Lines 7-10 | - |
| No global state between tests | PASS | `loginPage` is declared in describe scope but reset per beforeEach | - |
| Follows Arrange-Act-Assert pattern | PASS | All 3 tests have clear setup (beforeEach), action (signIn / openForgotPassword), assertion (URL or visibility check) | - |
| Includes teardown if creating data | PASS | No data creation; no teardown needed | - |
| File uses one top-level describe | PASS | Line 4 | - |

## 3. Assertions

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| Uses Playwright's auto-waiting expect | PASS | Lines 14-15, 25: `expect(page).toHaveURL`, `toBeVisible` | - |
| No weak assertions (`toBeTruthy`, `toBeDefined`) | PASS | All assertions are specific | - |
| One concept per test | PASS | Each test verifies one user-visible behavior | - |
| Failure messages are clear from assertion | PASS | URL regex + role-based locator give specific failures | - |
| Tests verify behavior, not implementation | PASS | No DOM internals; uses role-based locators | - |
| Error path assertions are specific | PASS | Line 20: assertErrorVisible includes expected message | - |

## 4. Isolation

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| Each test can run independently | PASS | No test depends on another's state | - |
| No shared mutable state between tests | PASS | `loginPage` is per-test (reset in beforeEach) | - |
| Tests don't share fixtures inappropriately | PASS | Page fixture is per-test by Playwright design | - |
| Order-independent | PASS | Reordering or running individually works | - |
| Cleanup doesn't depend on test success | PASS | No cleanup needed; if needed, place in `afterEach` not test body | - |

## 5. Performance

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| No `waitForTimeout` | PASS | None present | - |
| No `sleep` or `setTimeout` | PASS | None present | - |
| Uses Playwright auto-waiting | PASS | Lines 14-15, 20, 25 | - |
| Tests parallelizable | PASS | No shared state; can run in parallel workers | - |
| Reasonable per-test runtime expected | PASS | No expensive setup; ~5-10s per test estimated | - |

## 6. Maintainability

| Check | Status | Evidence | If FAIL, fix by |
|-------|--------|----------|-----------------|
| Uses Page Object Model | PASS | `LoginPage` imported; tests delegate UI interaction to POM | - |
| Uses role-based locators (not CSS) | PASS | Line 15: `getByRole` | - |
| Selectors localized in POM | PASS | No selectors in spec body | - |
| Imports are explicit | PASS | Lines 1-2 explicit | - |
| No commented-out code | PASS | None | - |
| No `console.log` debugging | PASS | None | - |
| Test data (credentials, URLs) externalized | FAIL | Lines 13, 19: inline credentials | Move to fixtures or a constants module |

## Score

**33 of 34 PASS**: a strong file with one improvement (and the file path still to confirm): extract test credentials to a named constants module or fixture so they're not duplicated across tests and don't leak into version control as plaintext.

Common pitfalls

  • Checklist gets generic (every check is 'has good naming?'): items should be SPECIFIC to spotted patterns.
  • Double-counting: one anti-pattern (e.g., shared state) fails 5 checklist items. Cluster these.
  • Evidence missing or vague ('see test file'): require line numbers.
  • Score calculation gets fudged when items are 'PARTIAL': force YES/NO and document partial in evidence.

Tips

  • Run on every NEW test file in PR review; catches issues before they propagate.
  • Pair with `review-test-code-anti-patterns`: checklist verifies breadth; anti-patterns drill into specific issues.
  • Tailor the checklist to your team's standards; add items for org-specific patterns (e.g., 'follows our test-id naming convention').
  • Re-run quarterly on existing high-value test files; quality drifts.

FAQ

How is this different from a linter?

ESLint and similar tools catch simple, syntactic issues. This checklist catches structural and design issues that need semantic understanding: naming clarity, isolation, assertion quality. Use both.

Should I automate the checklist in CI?

Some items can be automated (no waitForTimeout: ESLint rule). Most can't (assertion quality, isolation). Use checklist for human review; lint for what's machine-checkable.

What if my team uses a different framework?

Adapt the framework-specific items (`expect`, fixture patterns, etc.). The categories (naming / structure / assertions / isolation / performance / maintainability) are universal.

How do I calibrate to team standards?

Run the checklist on 5-10 representative files; agree as a team which items are most important. Document the agreed checklist in your contributing guide.