Back to Library
Iterative DebuggingIntermediate
Generate Tests to Isolate Bugs
Ask Claude to generate a failing unit test that reproduces a bug before fixing it—this creates a regression guard and clarifies the exact failure mode.
testingtddregression
The Strategy
Writing a failing test before a fix is classical TDD. With Claude, this two-step process is fast and ensures you have a regression guard. The test also clarifies the "done" criterion.
prompt.txt
<task>
Write a failing unit test that reproduces this bug.
Use Vitest. Do NOT fix the bug—only reproduce it.
</task>
<bug_description>
The formatCurrency function returns "$NaN" when the input
is a string-formatted number like "1234.56" instead of 1234.56.
</bug_description>
<code>
export function formatCurrency(amount: number): string {
return "$" + amount.toFixed(2);
}
</code>You might also need
Iterative DebuggingBeginner
The Error → Fix → Verify Loop
Structure debugging sessions as a tight loop: paste the error, get a fix, verify with the exact command, repeat.
debuggingerrorsloop
View snippet
Iterative DebuggingIntermediate
Hypothesis-Driven Debugging
Ask Claude to generate a ranked list of hypotheses for a bug before jumping to fixes—this avoids treating symptoms instead of root causes.
debuggingroot-causehypothesis
View snippet