It Ran Once. That Proves Nothing.

You wrote a function, ran it once with your own test numbers, and it printed the right answer. You moved on — and then your teacher ran it with an empty list, and it crashed. Or a classmate passed in one item instead of ten, and the answer was wrong in a way nobody noticed until the demo. The code was never correct. It was correct once, on one input, on your machine, in that moment.

This is the most common way student code fails, and it has nothing to do with talent. When you test by hand, you test the input you were thinking of while you wrote the code — the happy path. The bugs live everywhere else: the empty list, the single item, the zero, the duplicate. Hand-testing checks the case you already believed in. A real test checks the cases you forgot.

A Test Is a Promise You Can Re-Run

A test is a small promise written in code: given this input, this function returns that answer. You write it once, and then you can run it a hundred times — after every change, before every submission, at 2 a.m. before a deadline — and it either passes or it tells you exactly what broke. That is the whole idea. Everything else about testing is decoration around it.

You do not need a framework to make that promise. Python has assert built in: assert average([80, 90, 100]) == 90.0 either stays silent, which means the promise held, or it raises an error, which means something is wrong. No install, no new tool, no setup. The professional tools you will meet later — pytest, and the testing lessons in the Dev Workflow Basics course in CoderFile Lab — organise tests and run them in bulk. But the habit comes first: write down what the answer should be, then check it.

Your First Test in Five Minutes

Take a function you already understand — the average of a list of scores — and write the test before you trust the function. Paste the example below into the browser editor and run it. Three asserts, three promises, and one line at the end that runs them all.

# first_test.py — your first test, no framework needed
def average(scores): """Mean of a list of numbers, or 0.0 when the list is empty.""" if not scores: return 0.0 return sum(scores) / len(scores) def test_average(): assert average([80, 90, 100]) == 90.0, "three scores" assert average([50]) == 50.0, "one score" assert average([]) == 0.0, "empty list must not crash" test_average()
print("All 3 tests passed!")

It prints "All 3 tests passed!" — and the interesting part is the third assert. Without the two-line guard at the top of the function, average([]) divides by zero and crashes: sum([]) / len([]) is 0 / 0. That is the bug your hand-test never found. The test found it because the test was written to ask the question you forgot to ask. Run the example, then delete the guard and run it again: watch it fail on the third assert, and watch the failure point straight at the line that divides.

The Three Tests Worth Writing First

You do not need twenty tests. You need three, and they are the same three for almost every function a student writes. The normal case: a list of several scores, where the maths is ordinary. The smallest real case: a list with one score, where off-by-one mistakes and special cases hide. And the empty case: the empty list, the zero, the missing value — the input that means "nothing here" and that crashes more student code than any other.

That pattern travels. A function that finds the biggest number in a list? Test it with several numbers, with one number, and with an empty list. A function that counts words in a sentence? Test it with a normal sentence, with one word, and with an empty string. The shape is always the same: normal, smallest, empty. Three honest tests beat twenty copy-pasted ones that all check the same happy path.

When a Test Fails, Read It Like a Clue

A failing test feels like bad news, and students change everything at once, or delete the test. Both are mistakes. A failure is the most useful message your code can give you — it names the line, the values involved, and what was expected. Read it before you touch anything. The debugging routine starts the same way: reproduce it, shrink it, fix one thing, then prove it with the test.

There is one more possibility, and beginners miss it: the test can be wrong. If you wrote the expected answer by hand and got the maths wrong, the code is right and the test is lying. That is testing working: the disagreement between your code and your expectation is the thing to investigate, whichever side turns out to be wrong. Fix one side, run the test again, and never fix both at the same time.

Tests Are What Interviewers Actually Ask About

In an interview, nobody is impressed that your code ran once. What interviewers ask is what you did about the cases that could break it: what happens with no input, with one input, with bad input? Students who practise talking through their code already narrate the edge cases out loud. A test is that narration, written down: it proves you thought about the empty list before anyone asked.

It also changes how you build projects. A flashcard quiz, a grade tracker, a small tool for your class — every one of them has a function worth three tests. Write the tests as you build, not after you finish, and the project becomes a set of promises you can check. When something breaks a week later, the failing test tells you where, instead of re-reading everything.

When Your Test Snippets Outgrow Free, That Is the Upgrade Moment

Stay on Free ($0: 20 executions a day, 10 AI requests a day, 10 saved snippets, 3 private snippets, 3 collaborators per snippet) while it fits — three tests for one function, run a few times a day, fits easily. But a testing habit grows a library by design: every function you test becomes a saved snippet with its promises attached, and ten fills up fast. That is when Pro earns its $9/month or $69/year — unlimited saved snippets and executions, 100 AI requests a day, 10 collaborators per snippet, and GitHub integration, which Free does not include. Team ($19/user/month, or $15/user/month billed annually) covers a class testing each other's code.

Your next step takes five minutes, and it starts tonight. Open the browser editor, paste the average example from this article, and run it. Then delete the empty-list guard and run it again — watch it fail, put the guard back, and watch it pass. Save the file as a snippet, then write three tests for one function from your own coursework: normal, smallest, empty. That saved snippet starts a habit: from now on, your code does not just run. It proves itself.