Turn "I think it works" into a claim the machine checks every run — cover happy paths, edge cases, and invalid input, and lock in every fix with a regression test.
The refactoring lesson promised you could change code and keep behavior identical. But proving it by watching once lets bugs slip through — the same way "I tested it in Studio once" has fooled every developer who ever shipped. A test is a claim about your code written down in a form the computer can judge, on every run, forever. Not vibes, not memory — a verdict.
One test asserts one claim: given this input, the code produces this output. You've been meeting them all course — the check(condition, message) calls the sandbox grading throughout this course are tests:
check(addCoins(40, 10) == 50, "addCoins(40, 10) should return 50")
Read it as a sentence: "when I call addCoins with 40 and 10, I claim the result is 50." The machine runs it, and the verdict is binary — the claim holds, or it doesn't. No "kind of worked", no "looks right to me".
So what does a passing test actually prove? Exactly and only this: that specific input produced that result, on that run. It is strong evidence about one case, not a certificate for the whole game. addCoins behaving on (40, 10) says nothing about whether the save restores correctly, or whether the shop buttons are wired up — those need their own claims.
Your test suite passes check(addCoins(40, 10) == 50). What is exactly proven?
Multiply that: a handful of claims about each , dozens across a feature, and 'it works' stops being a feeling and becomes a stack of machine-checked facts.
Where do you point your claims? For almost any , four classes of inputs cover the interesting ground:
addCoins(40, 10) → 50.nil, an empty list. addCoins(95, 10) at a cap of 100 should clamp, not overflow.nil price, an item id that isn't in the shop. The should reject them, and you can test that it does.lookupPrice("InventedSword") must return nil, not crash and not return a price.Happy paths catch the obvious stuff; edges and invalid inputs catch the bugs that actually reach — the withdraw that goes negative, the cap that overflows, the crafted id that slips past the lookup. When a beginner asks "where do I even start testing", the answer is: start with case one, never stop at it.
Depositing the smallest valid amount — a single coin into a fresh wallet — tests the boundary of the function's range. That's an ___ case.
A failing test is only as good as its message. A test that fails with ok tells you something is wrong and nothing about what. A test that fails with a real sentence tells you what broke and where to look:
-- the message that files its own bug report:
check(addCoins(40, 10) == 50, "addCoins(40, 10) should return 50")
When that check fails, the output line is a bug report: the , the inputs, the expected result. You don't re-create the scenario in your head — it's already printed. Compare that to a tautology like check(true, "ok"), which can only ever pass and teaches nothing.
You can even see the pattern without a full harness — a self-verifying print that states the expectation in its fail branch:
local function addCoins(current, amount)
return current + amount
end
print(addCoins(8, 4) == 12 and "pass" or "fail: addCoins(8, 4) should be 12")
That and/or trick is a handy one-line assertion: condition and "pass" or "fail: <what and why>". The message half exists precisely so that when the day comes that it's wrong, whoever reads the output knows instantly what was supposed to happen.
Some code is a joy to test, and some is nearly impossible — and the difference is purity. A pure :
That's exactly what the sandbox can run. addCoins, salePrice, lookupPrice — provable in isolation, instantly.
Code that reads and writes the live game is a different story. A Touched handler, a RemoteEvent listener, leaderstats, a save — testing those means either running the whole game or stubbing out Roblox itself. The and playtesting lessons showed you the real-world way to check those: a real run in Studio. You can't drop every system into a sandbox.
The winning move is the one from your refactoring pass: keep the decision math pure, and keep the shell that touches the world thin. The that decides gets tested; the that connects gets kept small enough to see:
-- ServerScriptService: thin shell — touched, finds the player, delegates
sellButton.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
applySale(player.leaderstats.Coins, priceFor("Sword"))
end
end)
-- in a ModuleScript: pure decision, testable everywhere
local function applySale(coins, price)
if coins < price then
return false -- can't afford: no sale
end
return coins - price
end
Why does moving applySale out of the Touched handler make it testable?
Extract the pure core (refactoring), test the core (this lesson), eyeball the shell. That pairing is how a real game gets covered without inventing a Roblox simulator.
The most valuable test you'll ever write is the one you write before a fix. Here's the rhythm — it's called red, green:
Below is the wallet with two bugs: deposits can slip past the cap, and withdrawals can dip below zero. Your job: write your own claims about what should happen, run to see the red, then fix add and remove so every claim — yours and the hidden suite — goes green.
Working in the editor, first write at least three check() calls that describe correct behavior — a normal deposit and withdraw, a deposit that passes the cap, and a withdraw that passes the balance. Run: your cap and floor claims should fail on the buggy wallet. Then fix add() and remove() — clamp deposits at MAX_COINS and withdrawals at 0 — until every check passes. Keep the function names wallet:add and wallet:remove.
Hint: A deposit above the cap should land at exactly 100; a withdraw beyond the balance should stop at exactly 0. Those two rules are the fix.
Notice the order you did the work in: claims first, then the fix. That order is what makes the test trustworthy — it failed on the bug, passes on the fix, and will scream the moment the bug sneaks back.
A regression is a bug that returns after you fixed it. The classic way it happens: you harden a system, move on, and a month later an "improvement" quietly re-introduces the flaw. The Input Validation lesson ended with your shop handler rejecting item ids that aren't in the catalog:
local SHOP = {
Sword = 50,
Potion = 5,
}
local function lookupPrice(itemId)
local price = SHOP[itemId]
if price then
return price
end
return nil -- forged ids: no price, no sale
end
The day after the fix, everything worked. The dangerous question is next month: does it still? A regression test is the answer — the claim you write after a fix, and keep forever, that asserts the fixed behavior. If a future refactor deletes the nil return (maybe "cleaning up" that if), the suite turns red before any ever meets the bug:
Write the regression check that proves a made-up item id is still rejected — it must return nil, never a price.
-- the hardened lookup from the Input Validation lesson
local SHOP = {
Sword = 50,
Potion = 5,
}
local function lookupPrice(itemId)
local price = SHOP[itemId]
if price then
return price
end
return nil -- forged ids: no price, no sale
end
-- add your regression check belowThis is the refactoring lesson's promise fulfilled: you can change code fearlessly when a suite of claims watches the behavior. Unclear names, extracted , flattened nesting — safe, because every step that changes behavior is caught the instant it runs.
Your course has come a long way: two games fully built, an economy hardened against floods, saves that survive restarts, and code you can now clean and verify with confidence. The next lesson — Next Steps — pulls the whole course into one picture before you launch your next project.
Next: the map of everything you've learned — one full-system picture before the final project.