Types of software testing explained: unit, integration, end-to-end, regression, mutation tests and more
The main types of software testing are unit tests (one piece of logic, alone and fast), integration tests (real parts working together), contract tests (services that still agree), and end-to-end tests (the whole journey, like a user). On top of these levels come tests defined by their purpose (regression, smoke and acceptance), tests that check your tests (mutation testing), tests that hunt for cases nobody thought of (property-based and fuzz testing), and non-functional tests for performance and security. This guide explains what each one checks exactly and the rules that make it useful.
Video · Types of Software Testing Explained: Unit, Integration, E2E, Regression, Mutation Tests and More · 18:27
Types of software testing, in one paragraph
Prefer to watch? The 18-minute video walks through every type on this page with diagrams, and no code.
A test is a small program that checks another program. Every test has the same three steps: arrange a situation, act (do one thing), and assert that the result is what you expected. If it is, the test passes; if not, it fails and tells you what broke. (The same arrange, act, assert idea shows up when you validate an AI model's output in code.)
The different types of tests differ in how much of the system they exercise and what question they answer, from "is this calculation right?" to "can a real user pay?" to "would my tests even notice a bug?".
Throughout this guide we use one running example: the checkout of an online bookshop. It computes the total with any discount code, charges the card through a payment provider, saves the order in a database, and sends a confirmation email. Each part can break in a different way, which is exactly why there are different kinds of tests.
Two ways to sort tests: functional vs non-functional, black box vs white box
Functional testing checks what the system does: is the total right, is the order saved? Non-functional testing checks how well it does it: is it fast enough, does it survive the traffic, is it secure, can everyone use it?
Black box testing checks a system only from the outside, through its inputs and outputs, without looking at the code. White box testing uses knowledge of the code, for example to make sure every branch runs. Most real test suites mix both.
The test pyramid
The best-known picture in testing is the test pyramid, from Mike Cohn's book Succeeding with Agile (Martin Fowler):
| Level | How many | Speed | What a failure tells you |
|---|---|---|---|
| End-to-end | a few | minutes | something is broken somewhere |
| Integration | some | seconds | these parts do not fit together |
| Unit | many | milliseconds | this exact piece of logic is wrong |
The higher a test sits, the more realistic it is, and the slower, costlier and harder to debug.
The pyramid is a rule of thumb, not a law (The Practical Test Pyramid). Kent C. Dodds proposed the testing trophy for front-end apps: static analysis (types, linters) at the base and integration tests as the biggest part, because they give the most confidence for the effort (Kent C. Dodds). The lesson behind both shapes is the same: many cheap tests, a few expensive ones, and a clear purpose for each.
Unit testing: one piece of logic, alone and fast
A unit test checks one small piece of logic on its own, usually a function or a class. In the bookshop, that is the total calculation: three books at $20 with a 10% code should give $54. No database, no network, no payment provider: just logic in memory, so each test runs in milliseconds and you can have thousands.
The rules of good unit tests:
- Fast, so you run them on every change.
- Isolated: no test depends on another, or on the order tests run in.
- Repeatable: the same result every time, on any machine. No real clock, no random values, no network.
- One behavior per test, with a name that says which one: "an expired discount code is refused".
- Behavior, not implementation: rewrite the inside of a function and, if it still gives the right answers, the tests still pass.
Unit tests catch logic bugs and edge cases (an empty cart, a discount bigger than the price). What they cannot tell you is whether the pieces fit together: every part can pass its own tests while the whole thing fails.
Test doubles: stubs, fakes, spies and mocks
To keep a unit isolated, you replace its real neighbors with stand-ins called test doubles, a name from Gerard Meszaros' xUnit Test Patterns (Martin Fowler):
| Double | What it does | Bookshop example |
|---|---|---|
| Dummy | fills a slot, never really used | an empty customer object |
| Stub | gives fixed answers | a payment provider that always says "approved" |
| Fake | a simple working version | an in-memory database |
| Spy | records how it was called, checked afterwards | an email sender that remembers what it was asked to send |
| Mock | set up with the calls it expects; fails if they don't happen | "the payment provider must be charged exactly once" |
The rule: replace what is slow, unreliable or outside your control (the payment provider, the email service), not everything. A test that is mostly mocks only proves that your code calls your mocks (Mocks Aren't Stubs).
Integration testing: real parts working together
An integration test checks that two or more real parts work together. For the checkout: the order code with a real database. The test places an order, reads the database back, and checks the order is really there with the right total. This catches what unit tests cannot see: a wrong query, a missing column, a field saved in the wrong format, a bad configuration.
The rules:
- Use real dependencies where you can. Starting a real database in a throwaway container just for the tests is cheap today.
- Give every test a clean starting state, so no test leaks data into another.
- Test the seams. The unit tests already covered the logic; integration tests focus on where the parts meet.
Unit test vs integration test
| Unit test | Integration test | |
|---|---|---|
| Scope | one piece of logic | several real parts together |
| Dependencies | replaced by test doubles | real (database, queue, file system) |
| Speed | milliseconds | seconds |
| Catches | logic and edge-case bugs | wiring, queries, configuration, formats |
| A failure points to | one function | the boundary between parts |
Contract testing: services that still agree
When the checkout is split into services (a web app calling an orders service owned by another team), how do you know both sides still agree without running everything together? With a contract test. The consumer (the web app) records what it sends and what it expects back; that record is the contract. The provider (the orders service) then verifies the contract against its own code, on its own (How Pact works).
If someone renames a field, the contract fails before anything is deployed. The same idea applies to messages on a queue, not only to HTTP requests (for how requests and long-lived connections behave on the wire, see what a WebSocket is).
End-to-end testing: the whole journey, like a user
An end-to-end (E2E) test checks the whole system the way a user does. A robot opens a real browser, searches for a book, adds it to the cart, pays with a test card, and checks that the confirmation page appears. Everything is real: front end, back end, database, and a sandbox version of the payment provider. When it passes, you know the main user journey works.
End-to-end tests are slow (often minutes each) and fragile, so the rules are strict:
- Keep them few, and only for the journeys that matter most, such as signing up and paying.
- No flaky tests. A flaky test passes and fails with no code change, often because of timing. Fix it or remove it: a test nobody trusts is worse than no test.
- Expect them to say that, not where. A failing E2E test tells you something is broken; the lower levels tell you what.
Regression testing: a bug fixed once never comes back
Regression testing is not a separate level; it is a purpose. You rerun your existing tests after every change to make sure what worked before still works. A regression is something that used to work and broke again.
The most valuable habit in testing follows from it: every time you fix a bug, first write a test that reproduces it. The test fails, you fix the code, the test passes, and from then on it runs on every change, so that bug can never quietly return. Run automatically in your pipeline (see running checks in GitHub Actions), your whole test suite becomes your regression suite.
Smoke testing and acceptance testing
A smoke test is a quick, shallow check that the most important things work at all: the site loads, you can log in, you can reach the checkout, the payment page answers. It runs right after a deploy, in a minute or two; if it fails, you stop or roll back before testing deeper. The name comes from hardware: switch the device on, and if smoke comes out, there is no point testing further.
An acceptance test checks the system against what the business asked for. It is often written as plain sentences in the behavior-driven development style:
- Given a cart with three books
- When I apply a ten percent code
- Then the total drops by ten percent
Anyone on the team can read it, not only developers. User acceptance testing (UAT) is the final step, where real users or the client try the feature and confirm it is what they needed.
Mutation testing: test your tests
How do you know your tests are any good? Many teams measure code coverage, the share of lines that run during the tests. But coverage only says a line ran, not that anything checked its result. A test could run every line of the checkout, never check the total, and coverage would still read 100%.
Mutation testing answers the question honestly. A tool makes small, deliberate bugs in your code, one at a time. Each changed copy is a mutant:
| Original behavior | Mutant |
|---|---|
| free shipping above $50 | free shipping at $50 or above |
| subtract the discount | add the discount |
| send the confirmation email | skip the email |
Your tests run against every mutant. If a test fails, the mutant is killed: your tests noticed. If every test still passes, the mutant survived: that exact bug could ship. The share of killed mutants is the mutation score (Stryker docs). Because thousands of mutants each rerun the tests, teams run it on changed code or overnight, with tools such as PIT for Java and Stryker for JavaScript, C# and Scala.
Property-based testing and fuzz testing
Example-based tests use cases a person picked, and people pick the cases they already thought of. Property-based testing flips that: you state a rule that must hold for every input, and the tool generates hundreds of random inputs trying to break it. For the bookshop:
- the total is never negative;
- a discount never makes the price higher;
- removing a book and adding it back gives the same cart.
When the tool finds a failure, it shrinks it to the smallest input that still fails, such as a single book priced at zero. The idea comes from QuickCheck for Haskell (Claessen and Hughes, 2000); most languages have a version today, such as Hypothesis for Python.
Fuzz testing is a close cousin aimed at crashes and security holes. A fuzzer throws huge amounts of random, broken or strange input at a program and watches for crashes, hangs and memory errors. Modern fuzzers are coverage-guided: they keep and mutate the inputs that reach new paths in the code. They are especially good at finding security bugs in parsers, the code that reads files, images and network messages. Google's OSS-Fuzz runs this continuously on many open source projects.
Performance testing: load, stress, spike and soak
Performance tests are the main non-functional family (Grafana k6 docs):
| Test | Load shape | Question it answers |
|---|---|---|
| Load test | the traffic you expect | do response times stay acceptable on a normal busy day? |
| Stress test | beyond the expected load | where does the system break, and how? |
| Spike test | a sudden, short jump | what happens the moment a sale starts? |
| Soak test | normal load for hours | do slow problems, like memory leaks, appear over time? |
Measure throughput (requests per second), error rate, and latency as percentiles, not averages. The 95th percentile (p95) is the time that 95% of requests beat; averages hide the slow requests real users feel. Tools such as k6, JMeter and Gatling generate the traffic. (Behind a real site, the load usually lands on a load balancer first.)
Security testing
-
Static application security testing (SAST) reads the source code for dangerous patterns, such as user input going straight into a database query.
-
Dynamic application security testing (DAST) attacks the running application from the outside, the way an attacker would.
-
Dependency scanning checks your libraries against lists of known vulnerabilities.
-
Penetration testing is security experts trying to break in for real, with permission.
Four more types of testing you will hear about
-
Visual regression testing takes screenshots and compares them with approved ones, to catch layout changes nobody meant to make.
-
Accessibility testing checks that people using a screen reader or only a keyboard can use the app, and that text has enough contrast.
-
Chaos engineering breaks things on purpose, such as shutting down a server, to prove the system survives it. Netflix made it famous with Chaos Monkey (Principles of Chaos Engineering).
-
Exploratory testing is a person exploring the app freely, with curiosity. It finds the bugs nobody thought to write a test for.
Where each type of test runs in a CI pipeline
| When | Tests | Typical time |
|---|---|---|
| Every commit | static checks, unit tests | seconds |
| Every pull request | integration, contract | minutes |
| Before a release | end-to-end, acceptance (on staging) | tens of minutes |
| Right after a deploy | smoke | a minute or two |
| On a schedule | mutation, load, fuzzing, security scans | nightly or weekly |
The fastest tests run most often, so mistakes are caught minutes after they are made. That is what shifting left means. The same principle applies when an AI coding agent writes code: give it tests it can run, or wire them to run automatically after every edit with a hook.
For the bookshop, the whole picture looks like this:
| Feature | Test |
|---|---|
| Discount math | unit tests + a property test (the total is never negative) |
| Saving the order | integration test with a real database |
| Web app and orders service | contract test |
| Buying a book in a browser | one end-to-end test |
| After every deploy | smoke test |
| Before the big sale | spike test |
| Would the tests catch a bug? | mutation testing |
The main rules of software testing
- Test behavior, not implementation, so you can refactor freely.
- Get fast feedback first: cheap tests on every change.
- Keep tests deterministic, and never live with flaky ones.
- Every bug you fix gets a test.
- Treat coverage as a hint, not a goal; mutation testing tells you the truth.
- Many cheap tests, a few expensive ones, in whatever shape fits your project.
No single type of test is enough. Together, they let you ship with confidence. More guides like this one are in the article library.
Sources: Test Pyramid · The Practical Test Pyramid · Test Double · Mocks Aren't Stubs · The Testing Trophy and Testing Classifications · How Pact works · Stryker, mutant states and metrics · PIT · QuickCheck, ICFP 2000 · Hypothesis · OSS-Fuzz · Grafana k6, load test types · Principles of Chaos Engineering
FAQ
What are the main types of software testing?
By level: unit, integration, contract and end-to-end tests. By purpose: regression, smoke and acceptance tests. To check the tests themselves: mutation testing. To find unexpected inputs: property-based and fuzz testing. Non-functional: performance (load, stress, spike, soak) and security testing.
What is the difference between a unit test and an integration test?
A unit test checks one piece of logic on its own, in memory, with no database or network, so it runs in milliseconds. An integration test checks that real parts work together, such as your code with a real database, so it catches wrong queries, missing columns and bad configuration that unit tests cannot see.
What is regression testing?
Regression testing means rerunning your existing tests after every change to make sure what worked before still works. It is a purpose rather than a level: run automatically in your pipeline, your whole test suite becomes your regression suite, and every fixed bug should get a test so it cannot come back.
What is mutation testing?
A mutation testing tool makes small deliberate bugs in your code, such as turning a minus into a plus, and runs your tests against each changed version. If a test fails, the mutant is killed; if every test passes, it survived, which reveals a gap. The share of killed mutants is the mutation score, a more honest measure than code coverage.
What is the test pyramid?
A model from Mike Cohn's book Succeeding with Agile: many fast unit tests at the bottom, fewer integration tests in the middle, and a few end-to-end tests at the top, because tests get slower, costlier and harder to debug the higher they sit.
Read next
- Claude Code Best Practices: 10 Habits That Work
- Claude Code Hooks: Events, Examples and Exit Codes
- What Is a WebSocket? WebSocket vs SSE vs Polling vs HTTP
- Authentication vs Authorization: Sessions, JWT, OAuth, SSO
- Big O Notation Explained Simply, With Everyday Examples
- Software Engineering Unpacked: home
- The CCAR-F video playlist on YouTube