Test automation: what to automate, in what order and how to run it in CI
Automated tests are code that checks a product without a person and runs on every change. They pay off where a product lives and changes for a long time and where a bug in an important scenario is expensive: calculations, access rights, payments, integrations. The base of the suite is fast unit tests, above them integration tests, and at the top a few end-to-end scenarios; this shape is called the test pyramid. Automate first what is most dangerous to break, and wire the checks into CI so that a red suite stops a release.
Open the software development page
Automated and manual checks: where the line is
The big picture of software testing, including testing types in software testing, levels such as unit, integration and software system testing, and the role of manual checks, is covered in the guide to software testing types and levels. This guide is about the next step: turning part of those checks into an automated suite that works for years without becoming a burden.
An automated test is good where the answer is unambiguous: the total is calculated correctly or not, a manager can see other people's orders or not, an order gets the right status after payment or not. A person is needed where perception and common sense matter: is the screen clear, does the copy read well, is the path logical. So the question is not "manual or automated" but which of these checks a machine will do more reliably and more cheaply. Each type of software testing has its own answer.
When automated tests pay off
An automated test costs money twice: when it is written and when it is maintained as the product changes. It pays off if over its life it catches more expensive bugs or saves more manual checking than was spent on it. In practice this means:
- the product will evolve for months and years rather than ship once;
- releases are frequent, and a full manual regression before each one takes too long;
- the product handles money, personal data, roles and permissions, where bugs are costly;
- there are many integrations with external systems that change without warning;
- several developers work on the code, and one person's change can affect another's work.
The opposite is also true: a one-off promo landing page or a prototype that will be thrown away in a month does not need a large automated suite. Unit tests for any calculations and a careful manual check are enough there.
The test pyramid: how many tests at each level
The test pyramid is a simple model of how to spread effort. At the bottom there are many fast and cheap tests, at the top a few slow and expensive ones:
| Level | How many | Speed | What it catches |
|---|---|---|---|
| Unit | The most | Seconds for the whole suite | Errors in calculations, rules, input handling |
| Integration | Fewer | Seconds to minutes | Errors at the joints: database, API, queues, external services |
| End-to-end | A few | Minutes | Breakage of main user scenarios as a whole |
| Exploratory manual | As needed | Hours | Awkward spots and oddities that are hard to formalise |
A common mistake is an inverted pyramid, where almost everything is checked by end-to-end tests through the interface. Such a suite is slow, breaks with every layout change and shows poorly where the error actually is. If an end-to-end test fails while unit tests are green, that is a reason to add a lower-level test that catches the same problem faster.
What to automate first
Start not with covering everything but with risks. The order we use:
- Money and calculations: prices, discounts, taxes, stock levels, fees, everything computed on the server.
- Access rights: a user sees only their own data, a role without permission cannot perform someone else's action.
- The product's main scenario as one end-to-end test: sign-up or sign-in, the core action, payment or request submission.
- Integrations: what the system does if an external service returns an error, responds slowly or sends the same notification twice.
- Input validation: empty, overly long and deliberately malicious values in forms and APIs.
- Every bug found: fixed it, add a test so it does not come back.
Over time the last item gives the most value: the suite grows where the product actually broke, not where tests were easy to write.
Automated tests in CI: a gate before release
CI (continuous integration) is a server that automatically builds the product and runs checks on every change. Without CI, automated tests quickly become a suite that "used to work": people forget to run them and they quietly break. A typical setup:
- on every commit and merge request: lint, build and unit tests, so feedback arrives within minutes;
- before merging into the main branch: integration tests on a clean test database;
- before deployment: end-to-end scenarios in an environment close to production;
- on a schedule: long suites such as compatibility, dependency checks and load. More on load in the guide to load testing.
The main rule: a red gate means no release. Once a team gets used to shipping "with just one failing test, it is flaky anyway", the suite stops meaning anything.
Flaky tests and test data
A flaky test sometimes passes and sometimes fails with no change in the code. The cause is usually a dependency on time, run order, the network or data shared between tests. Such tests are more dangerous than missing ones: people get used to them, and a real bug gets lost among false alarms. A flaky test is either fixed at once or temporarily disabled with a repair task.
- each test creates its own data and does not depend on the results of others;
- time, randomness and external services are replaced in unit tests with controllable stubs;
- the test environment holds no real customer personal data, only synthetic data;
- secrets for test environments are kept outside the code, just like production ones.
Who writes and maintains automated tests
Developers write unit and integration tests together with the code: a change without a test is not considered finished. End-to-end scenarios are often owned by a QA engineer who knows the whole product and understands which paths matter to the business. But the whole team is responsible for a green suite, not one person.
Code coverage is useful as a hint about where there are no tests at all, but it is a poor goal. High coverage is easy to reach with tests that check nothing. A better question is which dangerous bugs this suite will catch, not how many lines it executed.
The suite needs upkeep: removing outdated tests, speeding up slow ones, rewriting fragile ones. Without time set aside for this, within a year the automated tests become a brake rather than a safety net.
Common automation mistakes
- Trying to automate everything at once and giving up a month later.
- Building the suite only from end-to-end tests through the interface.
- Not wiring tests into CI and running them by hand whenever someone remembers.
- Tolerating flaky tests and shipping with a red gate.
- Chasing a coverage percentage instead of checking risks.
- Using a copy of the production database with personal data as test data.
When a project is handed over, the automated checks are part of what the client receives: the suite must run without its author and be green. More in the guide to software project acceptance.
How we work with automated tests at JEEKSSHIRE 24
For us, automated tests are part of development, not a separate budget line. Money calculations, access rights and input handling are covered by tests together with the code, main scenarios are checked by end-to-end tests, and every deployment goes through build, lint and tests. If the gate is red, there is no release. We ship our own products by the same rules.
After launch the suite keeps working as part of software support and maintenance: every bug found becomes a new test. If you need a product that can be changed with confidence, describe the task on the custom software development page or see web app development.
Frequently asked questions
What are automated tests in simple terms?
Programs that check the product by themselves: they call functions, send requests, walk through scenarios and compare the result with what is expected. They run automatically on every change.
Can automated tests fully replace manual testing?
No. Automated tests reliably check unambiguous things such as calculations and permissions, while usability, copy and unexpected scenarios are still better seen by a person.
What is the test pyramid?
A model for distributing tests: many fast unit tests at the base, fewer integration tests in the middle and a few end-to-end scenarios at the top.
Where should test automation start?
With the most expensive risks: money calculations, access rights and the product's main scenario. After that it helps to turn every bug found into a test.
What is CI and why do automated tests need it?
CI is a server that builds the product and runs checks on every change. Without it people forget to run the tests, and they stop protecting against bugs.
What should be done with flaky tests?
Fix them at once or disable them temporarily with a repair task. A flaky test teaches the team to ignore red results, and a real bug slips through unnoticed.
Does an MVP need automated tests?
A minimal set, yes: tests for calculations, permissions and the main scenario. A large suite for a product that may change a lot after its first users is usually premature.
What code coverage percentage is needed?
There is no universal number. Coverage shows where tests are missing entirely, but what matters more is whether the suite catches dangerous bugs in money, permissions and key scenarios.