Please enable JavaScript to use CodeHS

Testing, QA, and CI

Integration & system testing

Unit tests prove that individual parts work. Integration tests prove that those parts connect correctly. System and end-to-end tests prove the whole product works the way a user expects.

Testing ~10 min High School / College Prep
The Big Idea

Integration tests

Two units can each pass their own tests and still fail when they are combined. Maybe one returns a number and the other expects a string. Maybe one sends a list and the other receives a single value. Integration tests catch those mismatches at the seams between modules.

Integration tests are broader than unit tests but narrower than system tests. They might test a database query layer with a real database, an API endpoint with a real HTTP call, or two classes working together.

Key idea: Unit tests answer “does this function work?” Integration tests answer “do these functions work together?”

Scope

System and end-to-end tests

System tests exercise the whole application. They check that the product meets its requirements from start to finish: a user can sign up, create a project, and export a file. System tests often use real or near-real environments.

End-to-end tests are a special kind of system test that simulate a real user. They open the app in a browser, click buttons, fill out forms, and verify the final state. They are the most realistic tests, but they are also the slowest and most fragile.

Safety

Regression tests

A regression is a bug that used to be fixed but comes back. Regression tests are tests written specifically to prevent a known bug from returning. They are often added after a bug is found in production.

Regression tests turn painful bug fixes into permanent guards. If a customer reports that checkout breaks when the cart has a coupon, the team writes a test for that exact case. From then on, every code change is checked against it.

Interfaces

The interface contract

Every connection between two pieces of code has an interface contract. One side promises to send a certain shape of data, and the other side promises to accept and handle it. Integration tests verify that contract from both sides.

When contracts are clear, teams can work in parallel. One person builds a function that returns JSON with three fields. Another person builds a function that consumes those three fields. As long as both sides honor the contract, the system fits together.

Interactive

Connect two components

Below are two functions. Each one has passing unit tests. Click Run integration test to see what happens when they are wired together, then click Fix the contract to make them agree.

get_price(item) unit test passed

Returns the price as a number: 10.50

↓

format_price(price) unit test passed

Expects the price as a string and prepends "$": "$10.50"

$ run integration test waiting...
Check Yourself

Quick quiz

1. What kind of test checks that two modules work together?

2. Which tests are usually the slowest and most realistic?

3. What is the purpose of a regression test?

Keep learning

You know how unit, integration, and system tests fit together. Next, see how continuous integration keeps all of these tests running automatically.

Part of the “Testing, QA, and CI” series.