Unit Testing
Testing that verifies individual functions, methods, or components work correctly in isolation from the rest of the application.
Unit tests are the smallest and fastest tests in a testing strategy. Each test targets a single 'unit' of code, such as a function that calculates shipping costs or a component that formats a date. Dependencies like databases, APIs, or other modules are typically replaced with mocks or stubs so the test only evaluates the logic under test.
A healthy codebase often has thousands of unit tests that run in seconds, providing immediate feedback during development. Frameworks like Jest, Vitest, pytest, and JUnit are commonly used for unit testing.
Why It Matters for QA Teams
Unit tests catch logic errors at the earliest possible stage, when they are cheapest to fix. They also serve as living documentation of how individual functions are expected to behave.
Example
A unit test for a calculateDiscount(price, percentage) function checks that calculateDiscount(100, 15) returns 85, that passing a negative percentage throws an error, and that a zero price returns zero regardless of the discount percentage.