Automated testing guide: unit, integration and end-to-end tests

What the main types of automated tests do, how much of each you need, and how to build a test suite that catches real bugs without slowing your team down.

By the UK Technology Hub teamPublished 4 minute read

The short answer

Automated tests check that code works as expected every time it changes. Unit tests check small pieces of logic quickly; integration tests check that components work together, including databases and APIs; end-to-end tests simulate real users through key journeys. Most teams need many unit tests, a solid layer of integration tests and a few end-to-end tests for critical flows, all running automatically in CI.

Manual testing catches some bugs, but it's slow, inconsistent and easy to skip under deadline pressure. Automated tests run the same checks every time, in minutes, so teams can change code confidently.

Types of automated tests

Unit tests

Check small, isolated pieces of code, such as a function that calculates prices or validates input.

Pros: very fast, precise, easy to write. Cons: don't catch problems between components.

Integration tests

Check that pieces work together: code talking to a database, an API endpoint returning the right data, services interacting.

Pros: catch real-world issues like wrong queries or broken contracts. Cons: slower and need test data and environments.

End-to-end tests

Simulate real users in a browser or app: sign up, log in, add to cart, check out.

Pros: test what users actually experience. Cons: slowest, most fragile and hardest to debug.

The testing pyramid

A common guideline:

  • Many unit tests at the base.
  • A good number of integration tests in the middle.
  • A few end-to-end tests at the top, for critical journeys.

Some teams prefer a "testing trophy" that emphasises integration tests. The principle is the same: balance confidence, speed and maintenance.

What to test first

If you're starting from nothing:

  1. Critical business logic: pricing, permissions, calculations, data validation.
  2. Key API endpoints.
  3. Your most important user journeys, such as checkout or booking.
  4. Bugs you've fixed, so they never return.

Tools

  • JavaScript and TypeScript: test runners such as Jest and Vitest; Testing Library for components; Playwright or Cypress for browser end-to-end tests.
  • Python: pytest.
  • Mobile: XCTest for iOS, JUnit and Espresso for Android, and framework tools for React Native and Flutter. Our mobile app testing guide covers mobile specifics.
  • API testing: test runners or dedicated API testing tools.

Writing good tests

  • Test behaviour, not implementation details.
  • Use clear names that describe what's being tested.
  • Keep tests independent.
  • Use realistic test data.
  • Make failures easy to understand.

Dealing with flaky tests

Flaky tests pass and fail randomly, often because of timing, shared state or external services. They erode trust. Fix or remove them quickly: use proper waits in end-to-end tests, isolate test data and mock unreliable external services.

Test data and environments

  • Use dedicated test databases, reset between runs.
  • Never test against production data containing personal information.
  • Mock or sandbox third-party services like payments and email.

Run tests automatically

Tests are most valuable when they run on every change through continuous integration. Our guide to CI/CD for small teams shows how to set this up.

Measuring test quality

Code coverage shows which code runs during tests, but high coverage doesn't guarantee good tests. Focus on whether tests catch real bugs and protect critical paths.

Testing AI features

AI outputs vary, so they need evaluation sets rather than exact assertions. Combine traditional tests for surrounding code with evaluations for AI quality.

Where to start in an existing codebase

Adding tests to a codebase with none can feel overwhelming. Start small:

  1. Add tests whenever you fix a bug, reproducing the bug first.
  2. Add tests for new features as you build them.
  3. Add a few end-to-end tests for the most important journeys.
  4. Gradually cover high-risk business logic.

Over months, coverage grows where it matters most, without stopping feature work.

Testing and refactoring

Tests make refactoring safe. Before restructuring code, add tests that capture current behaviour, then refactor while keeping tests passing. This is how teams improve old code without breaking things.

Test environments

Keep test environments as close to production as practical: same runtime versions, similar configuration and realistic data volumes. Differences between environments are a common source of bugs that only appear after release.

Making tests part of team culture

Include tests in code reviews, celebrate catching bugs early and make the test suite fast enough that developers run it often. A test suite people trust becomes one of a team's most valuable assets.

How we help

Our web app development team builds automated test suites into every project. Our app development and mobile app teams test across web and devices, running everything automatically before release.

Frequently asked questions

How many tests do I need?

Enough to give confidence that critical features work after every change. Start with key logic and journeys, and grow over time.

Are end-to-end tests worth the effort?

Yes for critical journeys like checkout or sign-up, but keep their number small because they're slower and more fragile.

What is test coverage?

The share of code executed during tests. It's useful but doesn't measure test quality on its own.

This guide is general information, not legal, tax or financial advice, and details such as prices, features and rules can change. Product and company names mentioned are trademarks of their respective owners and are used only to identify those products; UK Technology Hub is not affiliated with or endorsed by them.

Related guides

How to automate invoice processing, step by step

How businesses automate supplier invoice handling, from capture and data extraction to approvals and accounting entries, with sensible controls against errors and fraud.

All automation & integrations guides