Skip to content
BENIBIX Learn

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.

Development🧪 Testing & Quality

Unit Test

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

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.
Why it matters
They are fast and point at the exact function that broke. That makes them cheap to run on every save.
Full entry
Development🧪 Testing & Quality

Integration Test

A test that checks a few parts work as a team, like code and its data.

An integration test checks that several parts of a system work together. It might run your code against a real database, or call your own API and read the reply. These tests catch bugs that live between parts, like a wrong column name. They are slower than unit tests, often taking seconds each. Most projects have fewer of them than unit tests.

Example
Jack's unit tests all pass, but one bigger test fails. His code saves user_name, but the database column is called username.
Why it matters
Many real bugs live in the joins between parts. Unit tests cannot see them.
Full entry

In one line

Unit Test
A test that checks one small piece of code, like a function, by itself.
Integration Test
A test that checks a few parts work as a team, like code and its data.