Integration Testing vs End-to-End Testing: Contract or Journey?
A green integration suite can ship a broken checkout. Compare integration testing vs end-to-end testing on one runnable example and see where every check belongs.
A cart API stops sending one response header. The integration test that calls it passes anyway, because Cross-Origin Resource Sharing (CORS) is a rule browsers apply to scripts and a Python test is not a browser. In the test shop we built for this post, every shopper who types a promo code keeps seeing the full price, $80.00, with no error on the page.
You need both kinds of test, so the working question is where a given check belongs. We built a small checkout in Python and broke it twice. Every file below runs, so you can watch which level catches which break, and what that costs.
What you’ll learn
- What an integration test proves and what an end-to-end test proves
- One break both levels catch, with the message each one gives you
- One break our integration test passes and only a browser catches
- Two questions that place any check at the right level
What Is the Difference Between Integration Testing and End-to-End Testing?
An integration test checks that two components agree where they meet, and an end-to-end test checks that a user can finish a task through the real interface with the deployed services behind it. The first proves a contract. The second proves an outcome.
The integration test is quick, and when it fails it points at the exact field the two sides disagree on. The end-to-end test is slower, and it is the only one of the two that notices a problem outside the code, like a service that isn’t running or a setting that differs in the deployed app.
The names blur in the middle. Martin Fowler separates narrow integration tests, which exercise only the code in one service that talks to another, from broad ones, which need live versions of all the services. A broad integration test driven through the UI is most of the way to an end-to-end test. The table and the rest of this post use the narrow sense.
| Dimension | Integration testing | End-to-end testing |
|---|---|---|
| Question | Do these two components agree on what passes between them? | Can a user finish this task in the app as deployed? |
| Drives | Code, through a client call, a query or a message on a queue | The interface, through clicks, typing and screens |
| Runs against | The real component on the other side, or a stand-in checked against it | The whole stack, running where a browser or device can reach it |
| Usually written by | The developer who owns either side of the seam | QA engineers or developers, per user journey |
| A failure tells you | Which field, type or status the two sides disagree on | What the user saw go wrong, leaving you to find the cause |
| Cannot see | Browser rules, deploy settings and anything on screen | Which of the many parts it crossed caused the failure |
Integration tests prove two parts agree. End-to-end tests prove a user gets the result. Each check belongs at the cheapest level that can see its failure.
What Integration Testing Checks
Integration testing checks the seams, the places where one piece of your system hands data to another and both sides must read it the same way. The other side is either real, such as a database in a container, or a stand-in that someone checks against the real thing. A stand-in nobody checks is where integration suites go wrong, so decide where a mock can safely sit before the suite depends on it.
Typical checks at this level:
- Response shape: Field names, field types and required fields in what an API sends back
- Status and errors: The status code and error body a client branches on
- Storage round trips: A value written through your repository reads back unchanged
- Messages: An event on a queue carries what its consumer parses
Contract testing is the disciplined form of the first two. The Pact docs describe it as checking each application on its own so that the messages it sends or receives conform to a shared understanding. The consumer and the provider each test against the agreement, so neither needs the other running.
An integration test is quick to fail and quick to read, because it asks only whether two parts agree.
What End-to-End Testing Checks
End-to-end testing checks what a user can do, from the first screen to the result, with every real part in place. It drives the interface and asserts on what appears there. Anything between the click and the pixel can fail it, and that breadth is its whole value.
These failures live outside the code a narrow integration test calls:
- Browser rules: CORS, cookies, content security policy and mixed content
- Deploy settings: A frontend built against the wrong API URL, or a missing environment variable
- Rendering: A button covered by a banner, or a total that never updates
- Timing across services: A page that reads before the write behind it lands
End-to-end tests touch more moving parts than any other kind of test automation, so more things can turn them red. Keeping a large suite green is the subject of our end-to-end testing guide. An end-to-end test also catches failures no contract test was written for, because it sees what a user sees.
One Checkout, Two Breaks, Both Levels
Three small files make the split concrete. You need Python 3 and Playwright for Python (pip install playwright, then playwright install chromium), and the files go in one folder.
shop.py: A cart API and the checkout page that calls ittest_cart_contract.py: An integration test of the APItest_checkout_e2e.py: An end-to-end test that applies a promo code in a real browser
The Shop: One API, One Page
The API serves the cart total on port 8001. The page on port 8000 calls it when a shopper applies a code. A different port makes the page a different origin, so the browser lets the page read the API response only when the API sends a CORS header that allows it.
# shop.py: a cart API on port 8001 and the checkout page that calls it on port 8000
import json, threading
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
PRICES = [40, 25, 15]
PROMOS = {"SPRING10": 10}
def cart_body(code):
percent = PROMOS.get(code, 0)
total = sum(PRICES) * (1 - percent / 100)
return {"total": f"{total:.2f}"} # the page prints this string as it arrives
class Api(BaseHTTPRequestHandler):
def do_GET(self):
code = self.path.partition("code=")[2]
body = json.dumps(cart_body(code)).encode()
self.send_response(200)
self.send_header("Content-Type", "application/json")
self.send_header("Access-Control-Allow-Origin", "*") # lets the page on :8000 read it
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
PAGE = b"""<!doctype html>
<p id="total">Total: $80.00</p>
<input id="code"><button id="apply">Apply</button>
<script>
apply.onclick = async () => {
const r = await fetch("http://127.0.0.1:8001/cart?code=" + code.value);
const data = await r.json();
total.textContent = "Total: $" + data.total;
};
</script>"""
class Page(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.end_headers()
self.wfile.write(PAGE)
def log_message(self, *args):
pass
def start(handler, port):
server = ThreadingHTTPServer(("127.0.0.1", port), handler)
threading.Thread(target=server.serve_forever, daemon=True).start()
return server
The Two Tests
The integration test calls the API over real HTTP and checks the one thing the page depends on, that total arrives as a string ready to print.
# test_cart_contract.py: integration test of the response the checkout page reads
import json, unittest
from urllib.request import urlopen
import shop
class CartContract(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.api = shop.start(shop.Api, 8001)
@classmethod
def tearDownClass(cls):
cls.api.shutdown()
cls.api.server_close()
def test_promo_total_is_the_string_the_page_prints(self):
with urlopen("http://127.0.0.1:8001/cart?code=SPRING10") as r:
data = json.load(r)
self.assertIsInstance(data["total"], str)
self.assertEqual(data["total"], "72.00")
if __name__ == "__main__":
unittest.main()
The end-to-end test starts both servers and plays the shopper. It types the code in a real browser and waits for the total a shopper would read.
# test_checkout_e2e.py: a shopper applies a promo code in a real browser
import unittest
from playwright.sync_api import sync_playwright, expect
import shop
class Checkout(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.servers = [shop.start(shop.Api, 8001), shop.start(shop.Page, 8000)]
@classmethod
def tearDownClass(cls):
for server in cls.servers:
server.shutdown()
server.server_close()
def test_promo_code_updates_the_total(self):
with sync_playwright() as p:
page = p.chromium.launch().new_page()
page.goto("http://127.0.0.1:8000/")
page.fill("#code", "SPRING10")
page.click("#apply")
expect(page.locator("#total")).to_have_text("Total: $72.00")
if __name__ == "__main__":
unittest.main()
Run python -m unittest -v test_cart_contract test_checkout_e2e and both pass. Everything here ran on one Windows 11 machine with Python 3.14.0 and Playwright 1.60.0, busy with other work at the time. Over eight runs the integration test took 0.53 to 0.86 seconds and the end-to-end test 1.57 to 8.9 seconds. A toy shop keeps that gap small. In a real suite the end-to-end side also pays for a deployed environment and seeded data.
Break 1: The API Sends a Number
A backend developer changes total to a number, so other clients can do math with it. The change is one line in cart_body:
return {"total": round(total, 2)} # a number now, so other clients can do math
Both tests fail. Trimmed output, integration first:
AssertionError: 72.0 is not an instance of <class 'str'>
Ran 1 test in 0.589s
FAILED (failures=1)
AssertionError: Locator expected to have text 'Total: $72.00'
Actual value: Total: $72
Ran 1 test in 7.372s
FAILED (failures=1)
Same break, two reports. The integration failure names the field and the wrong type in half a second. The end-to-end failure shows the symptom a shopper would see, Total: $72, after about 7.4 seconds, because a Playwright assertion keeps retrying until its default 5-second timeout runs out. Both are correct. Only one tells you where to look.
Break 2: The CORS Header Goes Missing
Put the line back, then delete the Access-Control-Allow-Origin line instead, the kind of thing that happens when a handler moves behind a new proxy. Now the integration test passes:
Ran 1 test in 0.577s
OK
The end-to-end test fails, and the page goes on showing the full price:
AssertionError: Locator expected to have text 'Total: $72.00'
Actual value: Total: $80.00
Ran 1 test in 7.381s
FAILED (failures=1)
The browser console, captured in the same run, names the cause. The fetch from origin http://127.0.0.1:8000 was blocked by CORS policy because no Access-Control-Allow-Origin header was present. The MDN guide to CORS states the rule, that browsers restrict cross-origin HTTP requests initiated from scripts unless the response carries the right headers. Python’s urlopen applies no such rule, so our integration test had nothing to fail on.
You can pin the header with an assertion once you know it matters. The rule that blocked the page still lives in the browser, and only a browser test meets it by default.
| Change | Integration test | End-to-end test |
|---|---|---|
total becomes a number | Fails and names the field and type | Fails and shows Total: $72 |
| CORS header removed | Passes | Fails and shows the old Total: $80.00 |
TLDR: when both levels can see a break, the integration test tells you why. When only the browser can, the end-to-end test is the only one that will.
Two Questions That Decide Where the Next Test Goes
Before writing a test, split the failure you are guarding against the same way you would split a red build. Is it the contract, or is it the journey?
- Contract: Could a disagreement between two components cause this failure, and could a test of those two components see it? Write an integration test. Break 1 was a disagreement about a type, and the integration test caught it in half a second with the field named.
- Journey: Does the failure appear only with the real interface and the deployed services together, through browser rules, deploy settings or rendering? Write an end-to-end test. Our integration test passed Break 2, because the rule that broke the page only runs in a browser.
When both levels can see a failure, as with Break 1, write the integration test for the contract and keep one end-to-end test for the journey. The journey test is the one that catches next quarter’s Break 2.
| The check | Where it belongs |
|---|---|
| A field’s name or type in an API response | Integration |
| The error body a client parses on a 4xx | Integration |
| A price stored and read back at the right precision | Integration |
| The page can read the API at all (CORS, cookies) | End to end |
| The frontend calls the API the deploy points it at | End to end |
| The total a shopper reads after applying a code | End to end, once per journey |
Put each check at the cheapest level that can see its failure, and keep one journey test above every contract a customer depends on.
Picking Integration Testing Software and End-to-End Tools
For integration tests, start with the runner you already use for unit tests, such as pytest or JUnit. Add tools only for the seams that need them. Pact covers contracts between services, and container tools give a test a real database instead of a mock. Sort integration testing software by the boundary each tool exercises, since that decides which seams it can check.
For end-to-end tests, the choice is a browser framework or a hosted platform. Among frameworks, the deciding difference in Cypress vs Selenium is where tests run. Cypress runs inside the browser, so its tests are JavaScript. Selenium drives the browser from outside through WebDriver, a protocol any language can call. Playwright sits on Selenium’s side, since our Python test launched the browser and steered it. When you compare end-to-end testing software, weigh what each option costs to maintain, because a suite is kept for far longer than it takes to set up.
| Level | Start with | Add when |
|---|---|---|
| Integration | Your unit test runner and real HTTP calls | Contract tests once two teams own the two sides |
| End to end | One framework and the journeys a customer would notice | A hosted platform once maintenance eats the suite’s time |
Your Repo Keeps the Contracts, Pie Runs the Checkout Journey
Think back to Break 2, the missing CORS header. The API still sent the right total, but the browser kept it from the page, so the shopper saw the full price. Your integration tests stay next to the code they call, and Pie runs alongside them on the layer they cannot see. It is an agentic testing platform that follows a user’s path through your app, on web, iOS and Android. Our agents walk that path the way a shopper would and check the total on the screen, where that missing discount showed up. That is what AI-native means for a checkout test.
- Contracts stay in the repo: Your test runner and contract tests keep running on every commit, untouched by Pie.
- Journeys without scripts: Pie explores your app and turns the flows a user can reach, such as applying a promo code at checkout, into tests. Nobody on your team writes their selectors.
- Pull request runs: A
@pie-pr-bot testcomment on GitHub, or/pieon GitLab, starts a test of the change. A web app runs against its preview URL and a mobile app against an uploaded build.
Put the Check Where Its Failure Shows
The type change failed both tests, and the integration test said why in half a second. The missing header failed only in a browser, while the API test stayed green.
Write the contract test for anything two components can disagree about. Keep an end-to-end test for each journey whose failure only a user would see, and start with the one your last missing header would have broken.
Catch the Break Only a Browser Sees
Your integration suite keeps the contracts. Pie runs the journeys on the real screen.