Coding Workflows Workflow Intermediate

AI Test Generation Workflow

Build a test suite that fails for real reasons, not green decoration — coverage across unit, integration, and edge cases, then a review for the gaps.

The problem

Ask an AI to write tests for a file and you get a wall of assertions that cover the happy path and little else — they pass, they look thorough, and they'd miss the bug that actually ships. Tests only earn their maintenance cost if they fail when something is genuinely wrong. That takes understanding the behavior before writing assertions, building coverage in the right layers, and deliberately hunting the edges instead of restating the obvious.

Recommended workflow

Each step uses an existing NewPrompt tool, pre-filled by a matching resource. Open the resource to read it, or jump straight into the tool with the inputs ready.

  1. Pin down the behavior worth testing

    Get the AI to state, in plain terms, what the code is supposed to do — the rules, the inputs that matter, the outputs that count. Assertions written without this just freeze whatever the code currently happens to do.

    Outcome A clear statement of intended behavior to write tests against.
  2. Cover the core with unit tests

    Start where bugs are cheapest to catch: isolated unit tests for the core logic, one behavior per test, fast to run.

    Outcome Unit tests that pin the core logic and fail loudly when it breaks.
  3. Test the seams with integration tests

    Unit tests miss the wiring. Add integration coverage — and end-to-end where it earns its keep — for the boundaries: the database call, the API contract, the place two modules meet.

    Outcome Coverage where components actually connect, not just inside them.
  4. Hunt the edges

    Bugs live at the boundaries: empty, huge, duplicate, concurrent, malformed. Have the AI enumerate the edge and failure cases the happy-path tests skipped.

    Outcome Tests for the inputs that break things, not just the ones that work.
  5. Review the suite for blind spots

    Turn the review lens on the tests themselves: what behavior is still uncovered, which tests assert nothing useful, and where a passing test gives false confidence.

    Outcome A suite with its gaps named — and a short list of what to add.

Expected outcome

A layered test suite — unit, integration, edge — written against stated behavior and reviewed for gaps. The tests fail when something is genuinely wrong, which is the only property that makes them worth keeping.

Best for

  • Adding coverage to code that has little or none
  • Turning a vague 'write tests' into a real suite
  • Backfilling tests before a refactor or release

Not for

  • Pinning a single bug — the AI Debugging Workflow's test step is enough
  • Code whose behavior you can't yet describe — understand it first

FAQ

AI test generation workflow vs a unit test prompt: what's the difference?

A test-case prompt spits out assertions for code you paste in; this workflow decides what's worth testing first, then builds unit, integration, and edge coverage against that intent and reviews the suite for gaps. The output is a layered suite that fails for real reasons, not one batch of happy-path tests.

What does the AI test generation workflow produce?

A layered test suite spanning three levels — unit tests pinning the core logic, integration tests for the seams where components connect, and edge-case tests for empty, huge, malformed, and concurrent inputs — plus a review naming the behavior still uncovered and a short list of what to add.

How do I run the AI test generation workflow?

Work the five steps in order in your own AI tool. Start by having the AI state the intended behavior, then generate unit, integration, and edge tests layer by layer, and finish with the review step. You paste each batch into your test runner, run it, and fix or keep as you go.

How do I validate the quality of AI-generated tests?

Run the suite and confirm tests fail for the right reasons — mutate the code or break an input and check the relevant test goes red. Step 5 turns the review lens on the tests, flagging assertions that check nothing and passing tests that give false confidence. The pass or fail call stays yours.

Why understand the code before writing tests?

Tests written without knowing the intended behavior just freeze whatever the code does now, bugs included. Stating the intended behavior first means a failing test signals a real problem, not a deliberate choice.

Do I need the integration and edge steps every time?

Skip what doesn't apply. Pure logic might only need units and edges; a module full of I/O leans on integration. The review step is the one to always keep — it's what tells you what you missed.

Part of these projects

Complete build journeys that include this workflow as a stage.

Recommended next workflow

Tip: Each step's resource opens its tool pre-filled — start at step one and carry the output forward.