Loading lesson…
Writing a test first is not just good engineering. It is the clearest possible prompt for an AI. Let's use tests to make AI code reliable.
A test says: when I give the function this input, I expect exactly this output. That is the most precise way to describe behavior that exists. If you paste a failing test and ask the AI to make it pass, you get amazingly focused results.
# Step 1: write the tests first def test_add_positive(): assert add(2, 3) == 5 def test_add_negative(): assert add(-1, -1) == -2 def test_add_zero(): assert add(0, 42) == 42 # Step 2: paste the tests into your AI chat and say: # "Write the `add` function so all three tests pass." # Step 3: the AI almost always produces: def add(a, b): return a + b # Step 4: run pytest. If green, ship it.Writing the tests first gives the AI an unambiguous target. No room for misinterpretation.You do not need to write every test by hand. Give the AI the function signature, ask for test cases including edge cases, then review the list. You will often find a case you had not considered — that is the point.
| Language | Framework | Command |
|---|---|---|
| Python | pytest | pytest |
| TypeScript | Vitest | npx vitest |
| JavaScript | Jest | npm test |
| Go | testing (built-in) | go test ./ |
| Rust | cargo test | cargo test |
Tests are the only prompt that runs.
— A TDD-loving engineer
The big idea: a test is a prompt the machine can verify. Writing tests first turns every AI coding session into a tight loop: target, generate, check, done.
8 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-coding-tests-as-prompts-builders
What is the main idea of "Tests as Prompts — an Unexpected Superpower"?
Which concept is most central to "Tests as Prompts — an Unexpected Superpower"?
Which use of AI fits this topic best?
What should a careful learner remember about "Review before you run"?
You want to use AI after this lesson. What is the safest next step?
How should AI output about test-driven development be treated?
Name one way to verify an AI answer about test-driven development.
Which action would help you apply "Tests as Prompts — an Unexpected Superpower" responsibly?