Writing Test Cases Before You Code vs Testing Only After You Finish in Timed Mocks
Every coding round ends with the same question from the interviewer, said or unsaid: how do you know this works? There are two common ways candidates prepare for it. Some write a short list of test cases before they code, right after clarifying the problem. Others code first and test only once the solution looks finished.
Both habits show up in strong candidates. The difference is when the bugs get found, and how much of the clock is left when they do. Most people never compare the two on purpose. They test the way they always have at home, then discover in a live round that "I'll check it at the end" left them two minutes to fix an off-by-one.
This is a workflow comparison, not a rule every interviewer scores. Some interviewers ask for examples up front; others only care that you test before you say "done." What stays the same is that a bug found early is cheaper than a bug found late.
At a glance
| Category | Test cases before coding | Testing only after finishing |
|---|---|---|
| When bugs are found | Often during design | At the end, under time pressure |
| Upfront time cost | Two to three minutes | None |
| What the interviewer sees early | You thinking about edge cases | Momentum toward code |
| Risk | Over-planning simple problems | Running out of time to fix what you find |
| Best for | Problems with tricky inputs or boundaries | Short, familiar problems |
| What it trains | Edge-case instinct, clearer specs | Fast execution, end-of-round dry-runs |
What tests-first looks like
A typical opening after you restate the problem:
- Write three to five inputs as comments: one normal case, one empty or minimal case, one boundary case, and one case that looks designed to break a naive approach.
- Write the expected output next to each.
- Use the list to confirm your understanding with the interviewer ("For an empty array I'll return 0—is that right?").
- Plan the approach with those cases in mind.
- After coding, dry-run the same list instead of inventing new cases on the spot.
Honest strengths. Writing the cases often surfaces a misunderstanding before you have written a single line of logic, which is the cheapest moment to fix it. The list doubles as a clarification tool and gives the interviewer something concrete to agree with. At the end you do not have to think of tests while tired—you already have them. And it builds the habit interviewers often describe as "thinks about edge cases without being asked."
Honest limits. On a short, familiar problem, a formal list can feel like ceremony and eat minutes you want later. Some candidates write so many cases that planning becomes a stall. And a list written before you understand the approach can miss bugs that only appear in your specific implementation, such as an index you increment twice.
When tests-first wins: the problem has boundaries (indexes, empty inputs, duplicates, negative numbers); the prompt is ambiguous; you tend to misread problems; or you have lost rounds to bugs you found too late.
What testing-after looks like
The other habit saves checking for the end.
- Restate the problem and ask clarifying questions.
- Plan and code the solution with steady narration.
- When the code looks complete, pick a normal case and trace it line by line.
- Then try an edge case or two that come to mind.
- Fix what you find and say "done."
Honest strengths. You get to code sooner, which matters when the problem is simple and the round has a second part. The tests you choose afterward are shaped by the code you actually wrote, so they can target its real weak spots. For people who think best by building, it keeps momentum.
Honest tradeoffs. If the bug is in your understanding of the problem rather than in your code, you find it at the worst possible time. Tired, end-of-round testing tends to pick the easy case and skip the boundary one. And if the clock runs out, testing is the step that gets cut, which leaves the interviewer with unverified code.
When testing-after wins: the problem is short and you clearly understand it; the inputs have few edge cases; or the round has multiple parts and you need to move quickly through the first one.
Practicing the choice in timed mocks
The useful skill is a light version of tests-first that does not slow you down, plus the judgment to scale it to the problem. Timed mocks are where you build both.
- Pick one unseen problem and set a timer to your real round length.
- After restating it, give yourself ninety seconds to write test cases as comments. Stop at five.
- Code and narrate as usual.
- Before "done," dry-run your list. Note any bug the list caught that you would have missed.
- Afterward, write one line: did the upfront cases pay for their time on this problem?
Optional companion: Luna Interview is a Chrome extension framed as a practice / calm side panel—not a substitute for knowing the material, and never an "undetectable" live cheat. Keep it beside the editor during the mock while you own the cases, the code, and the dry-run.
Decision table for candidate situations
| Your situation | Prefer tests first | Prefer testing after |
|---|---|---|
| Problem has indexes or boundaries | Strong fit | Light |
| You often misread the prompt | Strong fit | Light |
| Short, familiar problem | Two quick cases only | Fit |
| You often run out of time | Ninety-second cap | Fit only if you reserve time to test |
| Multi-part problem | Light for part one | Fit for part one |
| Interviewer asks for examples | Strong fit | Write examples anyway |
| Day before the interview | Practice the ninety-second list | One confident warm-up |
A fair practical method (combine both in one week)
Timed mocks (three a week): One unseen problem each, with the ninety-second case list. Track two numbers: bugs your list caught, and minutes left when you said "done."
Case-writing drill (one short session): Read five problem statements and write only the test cases, with expected outputs. No coding. This makes the list fast enough that it rarely costs you much.
Late-testing check (one short session): Re-run an old solution of yours against your best edge cases and see what breaks. It shows you which kinds of bugs your end-of-round testing tends to miss.
Common mistakes / when NOT to use each
Skip a long case list when the problem is trivial, when you are writing cases to avoid starting, or when you have more than five. A short list beats a complete one.
Skip testing-only-after when the inputs have obvious traps, when you are unsure you understood the prompt, or when you know you tend to run out of time.
Skip timed-mock theater when you pause the clock to think of tests, re-use problems you already know, or test silently. Also skip any practice-tool framing that promises stealth help in a real employer interview—that is the wrong goal and the wrong integrity bar.
Soft close
If your bottleneck is finding bugs before the clock runs out, Luna Interview is a Chrome side panel built for that practice loop, not for cheating or replacing study. Soft trial path: https://lunainterview.xyz/
Write a few cases when the problem has traps. Code first when it truly does not. Practice the choice until it takes less than two minutes.
Rehearse with an AI interview copilot, then browse commonly reported interview questions.