Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 60 ยท Testing Fundamentals

Test Levels: Unit, Integration, System, Acceptance

Learn the four test levels, what each one targets and who owns it, the test pyramid and testing trophy, and how stubs and drivers isolate parts.

A product is made of small parts that work together to give users features. You can check it at the smallest scale (does this one function work?), at the scale of parts talking to each other, as a whole system, or in the eyes of the people who asked for it. These scales are called test levels. Each level has its own target, its own typical defects, and often its own owner.

Understanding the levels helps you answer practical questions: Where should this check live? Why is a failure in one test easy to diagnose and in another hard? Why can a product pass thousands of unit tests and still be unusable? This lesson explains the four classic levels, the pyramid and trophy shapes that describe a healthy mix, and the stubs and drivers used to isolate parts. It follows Testing in the SDLC, where the V-model first paired levels with development phases.

Four levels, growing scope

Unit One function or class on its own.
Integration Parts talking to each other.
System The whole product end to end.
Acceptance Does it meet the users' needs?

Each step up finds different defects, more slowly and more expensively.

1 / 2

Unit (component) testing

A unit test checks the smallest testable piece, such as a function, method or class, in isolation from the rest of the system.

  • Target: logic inside one piece: calculations, conditions, loops, edge cases.
  • Typically written by: the developer who wrote the code, often even before it (test-driven development).
  • Typical defects: wrong formulas, off-by-one errors, unhandled null values, broken boundaries.
  • Properties: very fast (milliseconds), precise (a failure points at one place), easy to automate and run on every change.

Because unit tests run in isolation, anything the unit depends on (a database, a network service, the clock) is usually replaced by a stand-in. We come back to those in a moment.

Integration testing

Parts that work alone may fail together: they disagree about data formats, call each other in the wrong order, or misread an error code. Integration testing checks the interfaces and interactions between components or between systems.

  • Target: the connections: function calls between modules, a service and its database, one system calling another's API.
  • Typically written by: developers and test engineers.
  • Typical defects: mismatched field names or types, wrong assumptions about error handling, missing data, timing and ordering problems.

There are two common sizes. Component integration tests join a few modules inside one system. System integration tests join separate systems, such as your shop and an external payment provider. Strategies for combining parts include big bang (everything at once, hard to diagnose), top-down, bottom-up and incremental (add one piece at a time), with the incremental ones making failures easier to locate.

System testing

System testing checks the complete, integrated product against its requirements, in an environment that resembles production as closely as practical.

  • Target: end-to-end behavior and also the non-functional qualities: performance, security, usability, compatibility, reliability (see Test Types).
  • Typically written by: an independent test team, or testers inside the product team.
  • Typical defects: a feature that fails only when features combine, wrong configuration, slow responses, data flowing incorrectly through a whole business process.

At this level, testers use the product the way users do, through the user interface or public API, and mostly treat the code as a black box.

Acceptance testing

Acceptance testing asks whether the product is fit for its purpose. It is the level where the main goal is not to find defects but to build confidence and decide whether to accept the product. It is closely tied to validation (see QA, QC and Testing).

  • Target: the business needs, workflows and acceptance criteria.
  • Typically done by: customers, product owners, business users, operations staff, or testers on their behalf.
  • Common forms:
    • User acceptance testing (UAT): real users check that the system supports their work.
    • Operational acceptance testing: operations staff check backup, restore, installation, monitoring and maintenance.
    • Contractual or regulatory acceptance: the product is checked against a contract or against laws and standards.
    • Alpha and beta testing: internal staff (alpha) and then selected real customers (beta) try the product in their own settings.

Stubs and drivers

To test a part alone, you must replace what it depends on and what calls it.

  • A stub stands in for a component that your code calls. It returns canned answers, for example a pretend payment service that always says "approved".
  • A driver stands in for a component that calls your code. It prepares input, invokes the part under test and checks the result, like a tiny test harness. A unit-test runner is a driver.

More general words are test doubles, with names such as stub, fake and mock (a mock additionally records how it was used so the test can verify the interaction). The details of mocks belong in automation tracks such as Jest or JUnit and TestNG; here the idea is what counts: control the surroundings so the failure can only come from the part under test.

flowchart LR
  D["Driver<br/>(calls the unit)"] --> U["Unit under test"]
  U --> S["Stub<br/>(canned answers)"]

The driver feeds the unit, the stub replaces its dependency, so a failing check can only come from the unit.

Seeing the levels in code

The stand-in below is a miniature shop. priceWithTax is a unit with pure logic. checkout combines the price calculator with a payment service. The first block runs a unit test of priceWithTax, then an integration check of checkout using a stub payment service, and then uses a real (stand-in) service with a driver that exercises the whole chain. Real systems have real databases and networks, which cannot run here, so everything is a small in-memory version.

JS A unit check, a stubbed check and an integration check

Press Run (or Ctrl + Enter) to see the console output here.

No output.

If the unit tests pass but an integration check fails, you know the problem is in how the parts fit together, not in the arithmetic. That narrowing of the search is the practical reason for having levels at all.

The test pyramid and the testing trophy

How many tests should live at each level? The test pyramid is a rule of thumb: many fast unit tests at the bottom, fewer integration tests in the middle, and a small number of slow end-to-end tests on top. The reasons are cost and speed: low-level tests are cheap to write, run in seconds and point at the cause, while high-level tests are slow, fragile and harder to diagnose.

The testing trophy is a variation popular in front-end work. It argues that integration tests give the best balance of confidence to cost, so the trophy has a few static checks at the bottom, some unit tests, the biggest layer of integration tests, and a handful of end-to-end tests on top.

Neither shape is a law. They are conversation starters, and the "ice cream cone" (too many slow UI tests, too few unit tests) is the anti-pattern both warn against. The stand-in below counts a team's suite and reports whether its shape resembles a pyramid, with fixed example data.

JS What shape is this test suite?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Levels versus types

Do not confuse a level (where in the system you test) with a type (what quality you test). You can run performance tests at the unit level (timing one function) or at system level (load on the whole site), and you can run functional tests at every level. The next lesson, Test Types, sorts out the types.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which test level is the best place to catch a mismatch between the field names that two services use?

    Interface problems between components show up when the components are tested together, which is the job of integration testing.
  2. 2. A unit test of a checkout function uses a fake payment service that always returns approved. What is that fake called?

    A stub stands in for something the code under test calls. A driver is what calls the code under test.
  3. 3. Which statement about acceptance testing is most accurate?

    Acceptance testing is about business needs and readiness for use, often by users or product owners, rather than hunting for every defect.
  4. 4. A team has 40 unit tests, 60 integration tests, 300 system UI tests and 90 acceptance tests, and the suite takes six hours. What pattern does this resemble?

    A heavy top and a thin bottom is the inverted pyramid anti-pattern: slow, fragile feedback and hard-to-diagnose failures.

Summary

  • The four classic levels are unit, integration, system and acceptance, growing in scope, cost and time to run.
  • Unit tests check logic in isolation; integration tests check the connections; system tests check the whole product; acceptance tests ask whether it is fit for purpose.
  • Stubs replace what the code calls, and drivers replace what calls the code, so failures can be pinpointed.
  • The pyramid and the trophy are rules of thumb for how many tests to place at each level, and an inverted pyramid is a warning sign.
  • Levels say where you test; types, covered next, say what you test.

Next up: Test Types: Functional, Non-functional, Structural, Change-related.