TDD With an AI Assistant: Red, Green, Refactor (unittest)
A first draft passed all five tests and still charged minus two pounds.
Video #171 ยท AI coding and productivity
Steps in the video
- 0:00 A first draft passed five of five tests and still charged minus two pounds
- 0:35 The idea
- 1:12 Setup
- 1:46 Step one: the spec
- 2:18 Red
- 2:39 Step two: a first draft
- 3:07 The case the spec forgot
- 3:38 The fix
- 4:03 Step three: refactor
- 4:37 What this does not show
- 5:06 Mistakes to avoid
- 5:31 My take and next steps
- 5:56 Recap
Files
- check.py (30 lines)
- draft1.py (13 lines)
- draft2.py (13 lines)
- final.py (15 lines)
- spec.py (26 lines)
- stub.py (5 lines)
Tested with
Python 3.12.15
What this does not show
No AI was run in this video: the first draft is hand-written to look like a typical assistant draft.
Sources
- https://code.visualstudio.com/docs/copilot/guides/test-driven-development-guide
- https://docs.python.org/3/library/unittest.html
- https://martinfowler.com/bliki/TestDrivenDevelopment.html
- https://newsletter.kentbeck.com/p/canon-tdd
- https://www.testsprite.com/blog/test-driven-development-in-the-age-of-ai-coding-agents
Learning IT by Example.