Skip to content
Commitwise
Menu

Unit test

A small, fast, automatic check that calls one piece of code with known input and compares the result with the expected value.

Definition

A unit test arranges input, acts by calling the code once, and asserts that the result matches a value worked out from the requirement. Unit tests run in milliseconds without network, database or real clock, so the whole suite can run after every change. Swift Testing, JUnit and Vitest are common frameworks.

In practice

A test checks that discountedCents(3000, percent: 10) returns 2700, and that 4999 cents of shopping still costs 499 cents of shipping.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.