Test-First Implementation and Bug Fixes
Get features and bug fixes implemented through observed failing tests, minimal changes, and verified regression checks.
Before & after
Same prompt, same agent — the only difference is the skill.
I can help you write a function to validate email addresses. Testing is definitely important, and I'd suggest using a testing framework like Jest or Vitest. You'll want to consider edge cases like special characters, domain validation, and RFC compliance. I can outline a general approach for you, and then we could implement the validation logic. Would you like me to start with some test cases, or would you prefer to begin with the implementation? I could also suggest some best practices for email validation if that would be helpful.
RED PHASE
1. Write failing test: validate('invalid.email') throws InvalidEmailError
- describe("Email Validator", () => { it("rejects addresses without domain", () => { expect(() => validate('invalid.email')).toThrow(InvalidEmailError); }); });
GREEN PHASE
2. Implement minimal code to pass: function validate(email) { if (!email.includes('@')) throw new InvalidEmailError(); return true; }
3. Add second failing test: validate('test@example') throws InvalidEmailError (missing TLD)
4. Expand implementation to check for TLD pattern
REFACTOR PHASE
5. Extract domain validation logic into separate helper
6. Consolidate regex patterns into constants
7. Add comment documenting RFC 5321 scope
TEST COVERAGE REPORT: 5 tests passing, 100% line coverage on validator.js. Diff preserved showing red-green-refactor transitions. Ready for production code review.About this skill
The code looks finished, but did the test ever catch the problem? This workflow requires an observed, meaningful failure before each behavior change, then implements the smallest fix and checks for regressions.
What it does
- Turns feature requests and bug reports into small, executable behavior tests.
- Distinguishes a useful failing assertion from broken imports, missing dependencies, and test-discovery errors.
- Keeps each implementation change tied to the test that justified it.
- Runs the focused test and full suite after each green step, reporting existing failures separately.
- Handles already-written code without falsely claiming that passing tests prove test-first development.
- Records red, green, and refactor evidence using actual commands and results.
What you get
An implementation or bug fix backed by tests that were observed failing before the change, plus a concise account of what passed and what remains unverified. If execution is unavailable, you get a provisional test and a precise verification blocker.
Best for
Engineers using Claude Code to implement functions, endpoints, and behavior changes, especially when generated tests tend to pass without proving that they can detect the bug.
SKILL.md preview
---
name: test-first-implementation-and-bug-fixes
description: >-
Implements features and bug fixes through an observed failing test, the minimum production change, full-suite regression checks, and refactoring on green. Checks failure causes and records execution evidence so passing tests cannot masquerade as test-first work. Use when the user says "write the test first", "implement this with TDD", "add a regression test before fixing it", "my tests pass but the bug is still there", "you wrote the implementation before the test", "add this endpoint with tests", or "cover this existing code before changing it".
---
# Test-First Implementation and Bug Fixes
… (sign up to view the full skill)More development skills
View all Development skills →React and Next.js Regression Test Coverage
Generate React and Next.js tests with Jest, Testing Library, MSW, and Playwright, prioritized by regression risk.
Playwright E2E Tests and Flake Repair
Build reliable Playwright tests, repair flakes from evidence, migrate suites, and configure faster, diagnosable CI.
Pre-Ship Verification for Code Changes
Before calling a code change done, Claude grades every claim by evidence, tries to break it, and reports what's verified vs assumed.
TestRail Case and CI Result Sync
Sync automated tests to TestRail cases and scoped runs with stable mappings, retry handling, and verified result counts.