Testing
After today, you can explain what unit, integration, and end-to-end tests each catch, and help a team decide where testing effort should go.
Dip your toes 1 min
Software teams write tests: small programs that run the product’s code and check that it gives the right answer. They run automatically every time an engineer changes something, so a bug gets caught in minutes on a laptop instead of by customers. Picture a shop that takes payments through Stripe Checkout, Stripe’s ready-made payment page. Stripe offers a test copy of its service where the card number 4242 4242 4242 4242 always succeeds and another number is always declined. That lets the shop’s tests try every outcome without moving real money. A test can type the declined number and check that the screen says the card was declined, rather than a vague “Something went wrong.” That test can exist only if someone drew the declined screen first.
The full lesson 10 min
Why this exists
Every time an engineer changes one line of code, something they didn’t touch can break. A shop’s checkout depends on the cart, the price rules, the tax rules, the payment form, and the confirmation email. A change to how discounts round can quietly break the total on the payment page. Nobody meant to touch the total, and nobody thought to check it.
You could ask a person to click through every screen after every change. That stops working fast. A product with a few hundred screens and a few dozen states per screen has thousands of paths. Teams merge changes many times a day. People also get tired and skip the boring paths, which are often the ones that break.
So teams write tests: small programs that run the product’s code and check that it does what it should. A test runs in seconds, never gets bored, and runs again on every change. The pipeline from Day 24 runs the tests before anything can merge.
The deeper reason is cost. A bug caught on an engineer’s laptop costs a few minutes. The same bug found by customers costs refunds, support tickets, and trust, and in payments it costs money directly.
What it is
A test is code that runs a piece of the product with known inputs and compares the result to the answer it expects. If they match, the test passes. If they don’t, it fails, and the automated checks on the pull request turn red. Tests live in the same repository as the code they check, often in a folder named tests or in files ending in .test.ts. The .ts marks a TypeScript file.
Take a simplified version of the Checkout shop from Day 20. The shop builds the cart and the order page, and Stripe hosts the page where the customer types their card.
The shop’s tests run against the sandbox from Day 5, where payments don’t move real money. In the sandbox, the card number 4242 4242 4242 4242 always succeeds, and 4000 0000 0000 0002 is always declined. Stripe’s testing docs list many more, one for each kind of failure. That gives the shop a safe way to try every outcome of a payment.
Teams sort their tests into three kinds, by how much of the product each one runs.
- Unit tests. A unit test runs one small piece of code on its own, usually a single function, and checks what it returns. The shop’s discount function is a good candidate. Each unit test runs in milliseconds, so a codebase can hold thousands.
- Integration tests. An integration test runs two or more parts together to check that they work as a unit. For the shop, that might be the backend saving an order to a test database, or creating a payment in Stripe’s sandbox. These take seconds each and need more setup.
- End-to-end tests. An end-to-end test drives the real product through a whole user flow, the way a person would. A program opens a browser, adds a product to the cart, clicks checkout, types the 4242 card, and waits for the order page. Tools like Playwright and Cypress do the clicking. Each test takes seconds to minutes.
Here’s what a unit test looks like. This one checks that a discount code takes the right amount off. Prices are stored in cents, so 5000 means $50.00.
test("SAVE20 takes 20% off the total", () => {
const total = applyDiscount(5000, "SAVE20");
expect(total).toBe(4000);
});
The first line names the test in plain words, so a failure reads like a sentence. The middle line runs the real discount function. The last line states the expected answer. If someone later changes the rounding inside the function and the total comes out as 3999, this test fails before the change can merge.
The testing pyramid comes from Mike Cohn’s book Succeeding with Agile, and it’s the most common way teams talk about the balance. The Practical Test Pyramid, by Ham Vocke, is the standard long read.
Tests higher up check more of the real product, so they catch problems the lower ones can’t. They’re also slower, cost more to write, and fail more often for reasons that have nothing to do with the change. Engineers call those flaky tests: tests that pass and fail on the same code, often because a page loaded slowly. A suite made mostly of end-to-end tests takes an hour and fails at random, and people stop trusting it.
One more idea makes the lower layers possible. A unit test for the shop shouldn’t call Stripe at all, because that’s slow and depends on the network. So the test swaps the real Stripe for a mock, a stand-in like Day 10’s that returns a fixed answer, such as “payment succeeded.” Mocks keep tests fast and predictable.
Their weakness is that a mock only knows what someone told it. If the real service changes its answer and the mock doesn’t, the unit tests stay green while the real checkout breaks. That gap is what integration and end-to-end tests are for.
A failing test is usually pointing at a regression, a bug in something that used to work. Catching regressions is what tests do best. When a team fixes a bug, a common habit is to write a failing test that reproduces it first. Then they fix the code until the test passes. That test stays in the suite for good, so the same bug can’t come back quietly.
How it shows up in your work
Your design states become test cases. When you design checkout, you draw the declined card, the expired session, the empty cart, and the discount code that doesn’t exist. Each of those is a test someone can write, and Stripe’s decline cards make the declined state easy to reproduce. If a state isn’t in the design, it often isn’t in the tests either.
Writing edge states into the acceptance criteria is one of the most direct ways a designer shapes what gets tested. You can also use the test cards yourself on staging to see each state for real.
Pull requests show test results near the bottom, as a list of automated checks with green ticks or red crosses. A red cross on the tests usually blocks the merge. Some teams also run visual regression tests, which take screenshots of each component and flag any pixel that changed. When you’ve asked for a visual change, those tests fail on purpose, and someone has to approve the new screenshots. On some teams, that someone is the designer.
Automated accessibility checks often sit in the same list. They catch missing labels and contrast failures, but not a bad focus order, the order in which the Tab key moves through a screen. That one is design review’s job.
When a check fails, the kind of test tells the team where to look. A failing unit test points at one function in one layer. A failing end-to-end test could mean a problem in any layer it passed through, or in the test itself. That’s why engineers often ask “which test failed?” before “what broke?”
Estimates include tests. When an engineer says a small feature will take three days, part of that is tests. Some of the time goes to writing new ones, and some to fixing old ones the change breaks.
A redesign of a flow can break dozens of end-to-end tests at once. Many end-to-end tests find a button the way a screen reader does, by its role and label. Rename “Pay now” and those tests break. Test IDs, hidden markers that let a test find an element however it looks, are the fallback when there’s no clear role or label. If an engineer asks whether a button’s label will change, they may be thinking about the tests.
The one thing people get wrong
“We’re at 90% coverage, so the code is in good shape.” That line treats test coverage as a quality score. Test coverage is the share of a codebase’s lines that run at least once while the tests run, usually shown as a percentage. It sounds as if 90% coverage means 90% of bugs get caught. It doesn’t.
Coverage measures what ran, not what was checked. A test can run a function and never look at the answer it gave. Some teams set a minimum, like 80%, and block merges that fall below it. That rule catches new code with no tests, but it can’t tell a careful test from an empty one.
Coverage also treats every line as equal. The line that calculates the amount to charge and the line that sets a footer link’s color count the same. Teams that chase a coverage number tend to write easy tests for easy code, because that moves the number fastest. Meanwhile the hard, risky parts, like what happens when a payment times out, stay thin. A high number can hide that.
Good teams decide where to test by risk instead. They ask two questions about each part of the product: how likely is it to break, and how bad would it be if it did? Code that changes often breaks often. Code that touches money, personal data, or who can see what is costly when it breaks.
The parts that score high on both get tests at every level of the pyramid. The parts that score low on both may get none, and that’s a reasonable choice, not laziness. Coverage still has a use as a flashlight: a part of the code with no coverage at all is worth a look.
Ask an engineer this
“If the most important flow in our product broke tomorrow, which test would catch it first, and how soon after the change would we know?”
The moment to raise it is when a change to a critical flow is about to merge, or while you’re planning one. Expect specific tests and a timeline: unit tests fail within minutes, an end-to-end test fails before the deploy, and production alerts catch the rest. A reply that leans on quality assurance (QA) staff spotting it by hand means the flow depends on people remembering to check. That’s worth knowing before launch day, not after. Follow up by asking which of your design’s edge states have tests and which don’t.
Terms from today
- Unit test
- An automated test that runs one small piece of code on its own, usually a single function, and checks the result it returns.
- Integration test
- An automated test that runs two or more parts of a product together, like the backend and a database, to check that they work as a unit.
- End-to-end test
- An automated test that drives the real product through a whole user flow in a browser or app, clicking and typing the way a person would.
- Test coverage
- The share of a codebase’s lines that run at least once during the automated tests, usually shown as a percentage.
- Regression
- A bug in something that used to work, introduced by a later change.