level 6Testing & Reliability
Unit test
also: unit tests, unit testing
A small automated check that tests one piece of code, like a single function, on its own.
a bit more technical
An automated test that exercises one small unit of code, usually a function or class, in isolation from databases, networks and other parts of the app. Unit tests are fast, so hundreds can run in seconds.
picture it
Testing each light bulb in the box before you install any of them. You learn each bulb works, but not whether the house wiring does.
why it matters
Agents often add unit tests to prove a change works. They are quick and useful, but they only prove small pieces work alone. Knowing that tells you when to ask for more.
what your agent might say
I added unit tests for calculateLateFee() covering on time, one day late, and 30+ days late. All 9 pass.
how you might use it
Write unit tests for the discount calculation function, including an empty cart and a 100% discount code.
common mistake
Thinking passing unit tests means the feature works. Each piece can pass alone while the pieces fail when joined together.
builds on