Unit testing means writing small, automated checks for the smallest testable parts of a program, such as a single function or class, and running each one in isolation from the rest of the system. Because each test is automated and self-checking, a developer can run the whole suite in seconds and learn immediately whether a change broke anything.
In their paper “Test Infected: Programmers Love Writing Tests,” Kent Beck and Erich Gamma describe how, using a framework like JUnit, “you can cheaply and incrementally build a test suite that will help you measure your progress, spot unintended side effects, and focus your development efforts.” The key move is that the test itself contains the expected answer, so it reports pass or fail without a human inspecting output.
This idea is delivered in practice by the “xUnit” family of frameworks. JUnit, described on its own site as “the programmer-friendly testing framework for Java and the JVM,” made automated unit testing routine for everyday programmers and inspired equivalents in nearly every language.
Fast, isolated unit tests are the foundation of two larger practices. Test-driven development writes the unit test before the code it checks, and continuous integration re-runs the full unit suite on every change so that regressions surface within minutes rather than weeks.