JIT Test Generation
Generate focused tests that catch regressions for code being changed right now.
The JIT approach: write tests at the moment of change, when context is freshest and the risk of regression is highest. Every change is a potential regression - catch it before it ships.
Reference: https://jeffbailey.us/blog/2026/02/14/what-is-just-in-time-catching-test-generation/
Workflow
Step 1: Identify Changed Code
git diff --name-only HEAD git diff --cached --name-only
If no changes exist, ask the user which files to target.
Step 2: Analyze Each Changed File
For each modified file:
- •Read the full file to understand its purpose and structure
- •Read the diff to understand what specifically changed
- •Find existing tests by searching for test files that import or reference the changed code
- •Identify uncovered paths - focus on:
- •New functions/methods without tests
- •Modified branches (if/else, switch) without branch coverage
- •Error handling paths that aren't tested
- •Edge cases in changed logic (null, empty, boundary values)
- •State mutations that could regress
Step 3: Prioritize What to Test
Generate tests in this priority order:
- •External API boundaries - Functions called by other modules or services
- •State mutations - Code that modifies databases, files, or shared state
- •Error handling - Catch blocks, error returns, fallback logic
- •Complex conditionals - Branches with multiple conditions
- •Recently changed hot paths - Code modified frequently (check git log)
Step 4: Generate Tests
For each test:
- •Follow existing conventions - Match the project's test framework, naming, and file organization
- •Test behavior, not implementation - Assert on outputs and side effects, not internal details
- •Use descriptive names - Test name should describe the scenario and expected outcome
- •One assertion per test - Each test verifies one specific behavior
- •Include edge cases - Null/undefined inputs, empty collections, boundary values
- •Use realistic test data - Not "foo"/"bar" but domain-appropriate values
Step 5: Validate Tests
Run the generated tests to confirm they pass:
# Detect and use the project's test runner # npm test, pytest, go test, cargo test, etc.
If tests fail, fix them. Tests that don't pass are worse than no tests.
Output Format
For each changed file, output:
## Tests for `path/to/changed-file.ext` **Changes detected:** [brief description of what changed] **Existing coverage:** [what tests already exist] **New tests generated:** [count] ### Test: [descriptive test name] **Covers:** [what regression this catches] **File:** `path/to/test-file.ext`
Then write the actual test files.
What NOT to Generate
- •Tests for trivial getters/setters
- •Tests that duplicate existing coverage
- •Tests that depend on implementation details (brittle)
- •Tests for generated/vendored code
- •Tests for configuration files
Test Quality Checks
Before finalizing, verify each test:
- •Has a clear, descriptive name
- •Tests one behavior
- •Would fail if the covered code regressed
- •Uses the project's existing test patterns
- •Doesn't require external services (mock them)
- •Runs in isolation (no test interdependence)