Writing Test Cases Before You Code vs Testing Only After You Finish in Timed Mocks

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

CategoryTest cases before codingTesting only after finishing
When bugs are foundOften during designAt the end, under time pressure
Upfront time costTwo to three minutesNone
What the interviewer sees earlyYou thinking about edge casesMomentum toward code
RiskOver-planning simple problemsRunning out of time to fix what you find
Best forProblems with tricky inputs or boundariesShort, familiar problems
What it trainsEdge-case instinct, clearer specsFast execution, end-of-round dry-runs

What tests-first looks like

A typical opening after you restate the problem:

  1. 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.
  2. Write the expected output next to each.
  3. Use the list to confirm your understanding with the interviewer ("For an empty array I'll return 0—is that right?").
  4. Plan the approach with those cases in mind.
  5. 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.

  1. Restate the problem and ask clarifying questions.
  2. Plan and code the solution with steady narration.
  3. When the code looks complete, pick a normal case and trace it line by line.
  4. Then try an edge case or two that come to mind.
  5. 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.

  1. Pick one unseen problem and set a timer to your real round length.
  2. After restating it, give yourself ninety seconds to write test cases as comments. Stop at five.
  3. Code and narrate as usual.
  4. Before "done," dry-run your list. Note any bug the list caught that you would have missed.
  5. 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 situationPrefer tests firstPrefer testing after
Problem has indexes or boundariesStrong fitLight
You often misread the promptStrong fitLight
Short, familiar problemTwo quick cases onlyFit
You often run out of timeNinety-second capFit only if you reserve time to test
Multi-part problemLight for part oneFit for part one
Interviewer asks for examplesStrong fitWrite examples anyway
Day before the interviewPractice the ninety-second listOne 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.