Lesson 1236 of 1570
Asking AI for the Test Before the Function
Have Claude or ChatGPT write the test, then write code until it passes — TDD made painless.
Lesson map
What this lesson covers
Learning path
The main moves in order
- 1The big idea
- 2TDD
- 3unit test
- 4red-green
Concept cluster
Terms to connect while reading
Section 1
The big idea
Writing tests first feels slow until AI does it for you. Ask Claude for the test, then write the code that turns it green — your function gets defined by what it should do, not what was easy to type.
Some examples
- You ask ChatGPT 'write a Jest test for a function that converts kebab-case to camelCase' and start with a failing test.
- Claude writes Vitest cases including the empty string and double-dash edge cases before you write a single line of the function.
- Cursor sees your test file and offers to scaffold the function signature that would satisfy it.
- Copilot Chat suggests two extra tests you didn't think of when you ask 'what edge cases am I missing?'
Try it!
Pick the next utility you need to write. Ask AI for three Jest or Vitest cases first, run them red, then write the function.
End-of-lesson quiz
Check what stuck
15 questions · Score saves to your progress.
Tutor
Curious about “Asking AI for the Test Before the Function”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Builders · 7 min
AI and Unit Tests: Write Tests That Catch Future You
AI writes solid tests for your functions so you don't break them later when you forget how they work.
Builders · 7 min
Asking AI to Write the Tests First
Telling Claude or ChatGPT to write tests before the function forces you to lock in what 'done' looks like.
Builders · 7 min
Letting AI Write a Test from the Bug Report
Turn a one-paragraph bug description into a failing test you can then fix.
