Select the search type
  • Site
  • Web
Search

Free Learning Enrollment

Get curated free lessons
tailored to your interests

Pick your topics and we’ll open your default email client with a prefilled enrollment request to rodclaar@effectiveagiledev.com.

  • Role-aware learning: Scrum, dev languages, web, DNN, AI tools & local LLMs.
  • Fast start: we’ll reply with links, playlists, and recommended next steps.
  • Self-contained module: all styling and logic is in this one block.

Enroll me in free learning

Opens your default email client (mailto). If you don’t have a mail app configured, use a webmail handler (Gmail/Outlook) or copy/paste the info into an email to rodclaar@effectiveagiledev.com.

Search Results

Rod Claar

Step 3: TDD with AI — Keeping You in the Driver’s Seat

Use AI to accelerate Test-Driven Development (TDD) without surrendering design intent or engineering judgment.

Step 3: TDD with AI — Keeping You in the Driver’s Seat

Objective
Use AI to accelerate Test-Driven Development (TDD) without surrendering design intent or engineering judgment.

The goal is not to let AI write your tests blindly. The goal is to use AI as a thinking partner while you remain the architect of the code.


Learning Path

1. Re-establish the TDD Loop

Before introducing AI, anchor on the classic cycle:

  1. Red – Write a failing test

  2. Green – Write the simplest code to pass

  3. Refactor – Improve design safely

AI should support this loop, not bypass it.

Key rule:

Tests define intent. AI assists implementation.


2. Use AI to Generate Test Ideas

AI is excellent at producing test scenarios you may not immediately think of.

Ask AI questions like:


 

Generate unit test scenarios for this function.
Include edge cases, boundary conditions, and failure cases.

Example function:


 

def calculate_discount(price, percentage):
return price * (percentage / 100)

Possible AI-generated scenarios:

  • Normal discount case

  • Zero discount

  • 100% discount

  • Negative percentage

  • Very large price values

  • Rounding behavior

Your job is to evaluate which tests reflect real system behavior.

AI suggests.
You decide.


3. Write the Tests Yourself

Do not copy-paste AI-generated test code.

Instead:

  1. Review the AI test ideas

  2. Select the meaningful ones

  3. Write the tests manually

This preserves:

  • understanding

  • design clarity

  • debugging ability

Example:


 

def test_zero_discount():
assert calculate_discount(100, 0) == 0


4. Compare Your Tests With AI Suggestions

After writing your tests:

Ask AI:


 

Compare these unit tests with your earlier suggestions.
What cases might still be missing?

This is where AI shines as a coverage reviewer.

You may discover:

  • missing edge cases

  • input validation gaps

  • boundary conditions


5. Implement the Code to Pass Tests

Now return to the TDD loop.

Let the tests drive implementation.

AI can help with:

  • implementation suggestions

  • refactoring

  • simplifying logic

  • identifying duplicated code

Prompt example:


 

Given these tests, suggest a simple implementation that passes them.
Do not add features not required by the tests.


6. Use AI for Safe Refactoring

Once tests pass, AI can help identify design improvements.

Ask:


 

Refactor this code while preserving behavior verified by the tests.
Focus on readability and simplicity.

Your safety net:

The test suite.

If tests pass, refactoring is safe.


Exercise

Goal

Practice using AI to expand test coverage while maintaining developer control.

Step 1 — Pick a Small Function

Choose something simple:

  • string parser

  • calculation function

  • validation logic

  • utility method


Step 2 — Ask AI for Test Cases

Example prompt:


 

Generate unit test cases for this function.
Include edge cases and failure scenarios.


Step 3 — Write Tests Yourself

Do not copy the AI output.

Instead:

  • read the suggestions

  • select meaningful ones

  • write tests manually


Step 4 — Compare Gaps

Ask AI:


 

Compare my tests with the earlier suggestions.
What important cases might still be missing?


Step 5 — Expand Coverage

Add the missing cases you agree with.

Your final test suite should reflect:

  • real requirements

  • edge conditions

  • error behavior


Key Principle

AI improves test discovery.

Developers maintain design ownership.

A useful mental model:

Role Responsibility
Developer Defines intent and architecture
Tests Protect behavior
AI Suggests cases and improvements

You stay in the driver’s seat.

Previous Article Step 2 — Boundaries first: modules, seams, and dependency direction
Next Article Step 5: Code Generation with Guardrails
Print
30 Rate this article:
No rating
Please login or register to post comments.

Search

Next steps

Choose your next step — Learn, Courses, or Videos.

Not sure where you came from? No problem. Pick the destination that matches what you want to do next.

Tip: If you want a guided starting point, choose Learn. If you want dates and registration, choose Courses. If you want quick wins, choose Videos.