Techment — Site Header

What is Unit Testing

Definition

Unit testing is the practice of testing individual units of code, such as functions or methods, in isolation to verify each behaves correctly on its own, providing fast, focused feedback that pinpoints exactly where logic breaks.
« Back to Glossary Index
  • Verifies individual functions in isolation, pinpointing failures precisely
  • Runs fast, giving developers near-instant feedback on changes
  • Acts as living documentation of how each unit should behave
  • Enables safe refactoring by quickly flagging broken logic

Real World Example

A developer writes unit tests for a currency-conversion function covering normal, zero, and negative inputs, so when a later change breaks the negative case, the failing test immediately points to the exact function.

FAQs

What is a unit in unit testing?

A unit is the smallest testable piece of code, typically a single function or method, tested in isolation from the rest of the system.

Why are unit tests valuable?

They give fast, precise feedback, document expected behaviour, and make refactoring safe by catching regressions immediately.

How do unit tests differ from integration tests?

Unit tests check pieces in isolation, while integration tests check that multiple components work correctly together.

Hello popup window