# Unit Test

> A test that checks one small piece of code, like a function, by itself.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** Unit Testing, Unit Tests

## Think of it like

Think of it like a box of bricks. You check each brick before you build.

## Definition

A unit test checks one small piece of code, like a single function, on its own. It gives the function an input and checks the output. It does not touch the network, a database or the disk, so it runs in a few milliseconds. A project can have thousands of them and still run them all in under a minute. Unit tests are the base of most test suites.

## Example

Emma's function adds VAT to a price. Her unit test checks that 100 becomes 120 at a 20% rate, in 2 milliseconds.

## Example code

```javascript
test('adds 2 + 3', () => {
  expect(2 + 3).toBe(5);
});
```

A unit test in Jest: one small check, no network, no database.

## Why it matters

They are fast and point at the exact function that broke. That makes them cheap to run on every save.

## Common mistake

Thinking passing unit tests mean the app works. The pieces can each be right and still not fit together.

## Three principles

- **One small piece.** Usually one function.
- **On its own.** No network or database.
- **Very fast.** Milliseconds each.

## Related terms

- [Integration Test](https://learn.benibix.com/term/development/integration-test)
- [Test Case](https://learn.benibix.com/term/development/test-case)
- [Function](https://learn.benibix.com/term/development/function)
- [Mock (Testing)](https://learn.benibix.com/term/development/mock)
- [Test Pyramid](https://learn.benibix.com/term/development/test-pyramid)
- [Arrange-Act-Assert (AAA)](https://learn.benibix.com/term/development/arrange-act-assert)

## Told apart from

- [Unit Test vs Integration Test](https://learn.benibix.com/compare/unit-test-vs-integration-test): A unit test checks one small piece of code by itself, in a few milliseconds. An integration test checks that parts work as a team, like your code and its database. Unit tests show which piece broke. Integration tests find the gaps between the pieces.

---

Source: https://learn.benibix.com/term/development/unit-test
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
