Fast tests and slow tests

Why you need it

Continuous integration only helps if the tests finish quickly. If every test opens the whole app and taps through it like a person, the tests take hours. Then every change waits, people stop waiting, and broken code slips in.

Think of it like this

Checking a car. You test each part on the bench in seconds: the brakes, the lights, the horn. Then you take the whole car for just a few test drives, because each drive takes an hour.

Where you’ll find it

  • Google: Asks for mostly small, fast tests and few big ones, as its testing team explains in Just Say No to More End-to-End Tests.
  • Fast-test tools: Jest for JavaScript and pytest for Python run thousands of small tests in seconds.
  • Slow-test tools: Playwright drives a real browser through the app, for the few tests at the top.

What to know first

Continuous integration. Every change is tested with main before it goes in. See Continuous integration.

Function. One small piece of code with an input and an answer, like "add tax to a price".

End-to-end test. A test that opens the real app and clicks or taps through it, the way a person would.

How it works

  1. Slow tests are slow. A test that taps through the whole app must start it, load screens and wait for each one. About a minute each. This is the wall of phones in the animation.
  2. Fast tests are fast. A test that calls one function needs no app and no screen. It takes a few milliseconds. Forty of them pass in about a second, as in the animation.
  3. Many at the bottom, few at the top. Most checks become fast tests on single functions. A middle layer checks a few pieces working together. A handful of slow tests at the top check that the whole app really works. This shape is the test pyramid.
  4. Keep the slow ones that matter. Do not delete every slow test. Keep one for each path that must never break, like signing up or paying. They catch what small tests cannot: the pieces not fitting together.

An example

Ana's app has 120 slow tests at 1 minute each: every change waits 2 hours.

Keep 10 slow ones (10 minutes). Turn the rest into 660 fast tests at 25 milliseconds each: about 17 seconds.

Ana's change now waits about 10 minutes instead of 2 hours, with more checks than before.

Further reading