Testing and quality · Concept

Unit tests

Small, fast tests that check one piece of code, such as a single function, on its own, by giving it inputs and checking the output.

Kinds of tests · updated

How it works

A unit test might call a calculateTotal function with a cart of two items and a discount code, then assert that the result is exactly what it should be. Because it touches no network, database or browser, hundreds of them run in a second or two, so developers run them constantly while working and CI runs them on every change.

Anything that would make a test slow or unpredictable, such as an API call or the current time, is swapped for a mock or a fake. Unit tests form the base of the testing pyramid: many cheap tests at the bottom, fewer integration tests above them and a handful of end-to-end tests at the top. They are good at pinning down logic and edge cases, and weak at proving the whole app works.

Unit tests vs the alternatives

More in Testing and quality

Kinds of tests

All 10 Testing and quality terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.