Test Cases Before Code
Why This Matters
If you ask an AI to “write tests”, it decides what is worth testing. It will test what the code does, including its bugs. If you first write down what the code should do, you have something to judge the AI’s tests against. Ten minutes of thinking before prompting is the cheapest quality step there is.
A test case is a sentence
A test case does not need code. It needs three things:
| Part | Question | Example for formatDuration |
|---|---|---|
| Given | What is the starting situation or input? | A duration of 63 000 ms |
| When | What happens? | It is formatted for the table |
| Then | What exactly should the result be? | 1m 03s |
If you cannot write the Then precisely, you do not yet know what correct means, and neither does the AI.
Three techniques that find most bugs
- Equivalence classes. Group inputs that should behave the same, and pick one from each group. For
formatDuration: under 10 s, 10 s to a minute, a minute or more, invalid. - Boundary values. Bugs live at the edges. Test just below, on, and just above each boundary: 9 999 ms, 10 000 ms, 59 499 ms, 59 500 ms, 60 000 ms.
- Error cases. What should happen with wrong input? A negative duration,
NaN,Infinity.
Your test list for formatDuration
| # | Given (ms) | Then | Why |
|---|---|---|---|
| 1 | 400 | 0.4s | Below 10 s: tenths |
| 2 | 9 999 | 10s | Boundary: rounds up across the limit. Correct? Decide! |
| 3 | 10 000 | 10s | Boundary |
| 4 | 42 000 | 42s | Seconds |
| 5 | 63 000 | 1m 03s | Minutes, zero-padded seconds |
| 6 | 600 000 | 10m 00s | Zero seconds still padded |
| 7 | -1 | error | Invalid |
| 8 | NaN | error | Invalid |
Row 2 is interesting: the code returns 10s, which looks right but comes from the “under 10 seconds” branch. Is that the intended behaviour? A question like this is a finding you take to the developer or product owner. That is testing, and no AI would have asked it for you.
Use AI to challenge your list, not to write it
After you have your own list:
Here are my test cases for formatDuration (code below). Which important cases am I missing?
Do not write code. Answer as a table: input, expected output, why it matters.
Merge the good suggestions and reject the rest. You stay the owner of the list.
Exercise
- Write your own test list for
formatDurationbefore looking at the table above. Compare. - Ask your AI assistant to challenge your list with the prompt above. Which suggestion was useful, and which was not?
- Write five test cases in Given/When/Then form for the status filter on the TestRun Board page (“show only failed runs”).
Key Takeaways
- Write test cases before any code exists, in plain Given/When/Then.
- Equivalence classes, boundary values and error cases find most bugs.
- Questions about intended behaviour are findings, not failures.
- Let AI challenge your list; you remain the owner.