Unit testing

Edit · View history

Unit testing

Unit testing is a software testing method in which individual components or units of a program are tested in isolation to verify that each performs as designed. A unit is the smallest testable part of a program, often a function, method, or class. The practice is a cornerstone of test-driven development (TDD) and helps ensure code quality, facilitate refactoring, and catch defects early in the development cycle.

Characteristics

Benefits and drawbacks

Benefits include early bug detection, documentation of code behavior, and safer refactoring. Drawbacks include the need to maintain test code, the difficulty of writing tests for legacy code, and the risk of false confidence if tests are poorly designed. Unit testing alone cannot catch integration or system-level issues.

History

Unit testing became prominent with the rise of extreme programming in the late 1990s, which popularized test-driven development. Early unit testing frameworks like SUnit (for Smalltalk) by Kent Beck laid the foundation for later tools such as JUnit for Java, which became a standard in the mainstream software industry.