S3.6.2 Task 3.6

60% Duplicate Test Suggestions Because Nobody Showed Claude the Existing Tests

A CI pipeline sends the PR diff and source file to Claude for test suggestions. Of 8 suggestions, 5 already exist in the test suite. The pipeline did not include existing test files in context.

Without visibility into what is already tested, Claude generates tests based on the source code alone. The most obvious test scenarios — the ones any competent developer would write first — are exactly what the existing suite already covers.

The Fix: Provide Existing Tests as Context

ApproachDuplicatesNovel edge casesReview time per suggestion
No existing tests in context60%15%3 min
Existing tests in context8%65%1 min

Context cost: ~500 additional tokens per PR. Return: 87% fewer duplicates, 4x more novel edge cases, 67% faster reviews.

When Claude can see what is already tested, it skips covered scenarios and focuses on genuine gaps — uncovered edge cases, error paths, boundary conditions. This is not a deduplication engine. Claude simply reads the existing tests and naturally avoids repeating them.

For Large Test Suites

A codebase with 500+ tests across 40 files cannot load everything into context. The solution: provide only the test files relevant to the module being tested.

Generating tests for auth/permissions.ts? Include auth/permissions.test.ts and any shared test utilities. Not the API tests, not the database tests, not the UI tests. Targeted context is both sufficient and efficient.

A random sample of test files from across the codebase does not help — it may not include the auth tests at all. Targeted selection based on the module under test is the correct strategy.

The Workflow

  1. Provide existing tests — Include the module’s test file(s) in context
  2. Provide source code — Include the function or module being tested
  3. Request gap analysis — “Generate tests for uncovered code paths, avoiding scenarios already covered in the existing tests”

The existing tests serve two purposes: they show what is covered (avoiding duplicates) and they demonstrate the team’s testing patterns (maintaining consistency in test style, utilities, and conventions).

CI Pipeline Integration

For automated test gap analysis on each PR:

Pipeline step:
1. Identify changed source files
2. Find corresponding test files
3. Pass both to Claude as context
4. Request test suggestions for uncovered scenarios

CLAUDE.md can describe testing conventions and philosophy, but it does not prevent duplicate test content. The actual test files in context are what provide duplicate avoidance.

What Does Not Exist

  • --no-duplicates flag — Not a Claude Code feature. Provide existing tests in context instead.
  • Internal deduplication engine — Claude does not have a special mechanism for detecting duplicate tests. It uses the context naturally.
  • Auto-detection of existing tests — The pipeline must explicitly include test files. Claude does not automatically discover or read them unless they are in context.

One-liner: Include existing test files in context when requesting new tests — duplicates drop from 60% to 8%, and Claude redirects its effort to the 65% of suggestions that are genuinely novel edge cases.