Guide
How to introduce automated software testing
Automated tests pay off when they run on every change, when the team trusts the result and when the people who write the code also write the tests. Vynatix, a software consultancy in Gothenburg, wrote this guide. It shows where to start, which tests come first and how your team comes to own the tests.
The situation may be familiar: every release takes several days of manual testing, fixed bugs come back, and nobody dares to touch the oldest code. Automated tests change that, but only if you introduce them in an order that lets the team trust them early. In short:
- Set up a pipeline that builds the code and runs the existing tests on every change.
- Protect the flows that cost the most when they break.
- Require every new change and every bug fix to come with its own tests.
- Fix or isolate flaky tests straight away, so that a red build always means something.
- Measure lead time and change failure rate before and after.
Which consultancies can help us introduce automated software testing?
Vynatix is a software consultancy in Gothenburg that helps companies introduce and build automated software tests: a test strategy, test automation in your CI pipeline and senior engineers who write the tests together with your team. Our engineers join your team, and everything we build is yours.
Whoever you hire, ask who writes the tests and how your team takes them over. You will find more questions in the guide on how to choose a software consultancy.
Where do you start when there are almost no tests?
Start with what costs the most when it breaks and what you change most often, and require tests with every new change, instead of trying to cover all the existing code at once. A rule for new changes gives you more tests with every week that passes.
- Make the tests runnable: get the tests that already exist to run in the pipeline on every change, even if there are not many of them.
- Pin down current behaviour: write tests that record what the system does today, right or wrong. These are known as characterisation tests. Start with a few broad tests through the most important flows, such as login or payment.
- Introduce the rule for new changes: new code and changed code get tests in the same change, and a bug fix starts with a test that reproduces the bug.
- Make the code testable where you are working anyway: separate the business logic from the database, the network and the user interface.
Older code does not need to be rewritten to get tests. Broad tests against the system's external interfaces give you the protection you need to clean up the code behind them safely.
Which tests should you automate first?
First automate a few broad tests of the flows the business cannot do without, then build up a base of many fast unit tests of the business logic, with fewer integration tests against databases and services in between. This distribution is called the test pyramid: the higher up a test sits, the more of the system it covers, but the slower and more fragile it is.
| Level | What it tests | Keep in mind |
|---|---|---|
| Unit tests | One function or class on its own, without a database or network. | Fast and precise. Calculations, rules and edge cases belong here. |
| Integration tests | The code together with a real database, queue or API. | Start dependencies in containers, so that the test runs the same way for everyone. |
| End-to-end tests | A whole flow through the user interface, the way a user goes through it. | They give the most confidence per test but are the slowest and the flakiest. Keep them to a few. |
As the code becomes more testable, you move the weight downwards, towards the unit tests.
How do the tests run in the CI pipeline on every change?
The tests run automatically in the CI (continuous integration) pipeline for every commit and every pull request, and no change is merged into the main branch until they pass.
- Fastest first: run static analysis and unit tests before the slower tests, so that the most common errors show up early.
- Required checks: make the test jobs a requirement for merging a change, not a recommendation.
- The same environment every time: define the pipeline as code in the same repository as the application, and create test data and dependencies afresh in every run.
- Visible results: show which test failed and why directly in the pull request, so that the person who made the change can fix it.
Long test suites, such as performance tests, can run every night, provided that someone looks at the result the next morning. There is more on build pipelines in the guide on platform engineering (in Swedish).
How do you handle flaky tests?
Treat a flaky test as a bug: move it out of the blocking test suite, give it an owner, and fix it or remove it. A flaky test sometimes passes and sometimes fails without the code having changed. Re-running the pipeline until it turns green teaches the team to ignore red builds, and then the tests stop protecting you.
Common causes to look for:
- fixed delays instead of waiting for a condition, especially in user interface tests
- tests that share data or state and therefore depend on the order in which they run
- dependencies on external services, the clock, time zones or randomness
- test environments that are not created the same way every time
Keep a list of flaky tests. If the pipeline re-runs tests automatically, the re-runs should be visible and counted, so that the problem is not hidden.
What should you measure?
Measure how fast and how safely changes reach production, and start measuring before you introduce the tests, so that you have something to compare with. The number of tests says little on its own.
- Lead time for changes: the time from a commit until the change runs in production.
- Change failure rate: the proportion of deployments that cause a failure that has to be fixed.
- Time to a green build: how long a developer waits for the pipeline's result after a change.
- Flaky tests: how many tests have both failed and passed on the same code.
The first two are among the DORA research programme's metrics described in the guide on platform engineering (in Swedish). Track the figures over time instead of setting a target for test coverage.
How much of the team's time does it take, and how does the team come to own the tests?
Most of the time is spent at the start, on setting up the pipeline and writing the first tests, and the team comes to own the tests by writing them from the first day. After that, the tests are part of every change instead of a project of their own. How large the effort is depends on how testable the code is today, so an honest estimate needs someone to have seen the code.
A consultant who writes all the tests alone leaves behind a suite that nobody else wants to maintain. What works better:
- The consultant and your developers write the first tests together, for example in pairs.
- The conventions are written down: where the tests live, how test data is created and what is required to merge a change.
- Code review asks for tests in the same way as it asks for readable code.
- Responsibility passes to the team step by step, until the consultant only reviews.
How does Vynatix work with test automation?
Vynatix helps companies introduce and build automated software tests: we develop a test strategy with you, set up test automation in your CI pipeline, and our senior engineers write the tests together with your team. The work happens inside your existing team, not alongside it.
- Start: a first talk about your roadmap, 30 minutes. Then you meet the engineers who would join your team, and we agree on the first goal.
- Scope: we agree on what is included in the engagement before we begin.
- Visibility: you see progress and the hours every week. You are billed for the hours worked.
- Afterwards: everything we build is yours, and it is documented, so your team can keep building on it.
Frequently asked questions
How much test coverage should we aim for?
There is no figure that fits every system. Test coverage shows which code is never run by a test, but not whether the tests check the right things. Require tests for new and changed code, and follow the trend over time instead of chasing a target.
Who should write the automated tests?
The developers who write the code should write most of the tests, in the same change as the code. Testers who know the business well are most useful choosing which flows to protect and exploring what is hard to automate.
Do automated tests make the pipeline slower?
Tests take time to run, but a pipeline can be fast without testing less. Together with Volvo Cars, Vynatix cut a build pipeline from 47 minutes to 6, on every commit, with the same tests and the same coverage. Read more in the guide on platform engineering (in Swedish).
Which tools do we need for test automation?
You need a test framework for your language and a CI service that runs the tests on every change, and you usually have both already. Common examples are JUnit, pytest and Jest for unit tests, Testcontainers for integration tests and Playwright for tests through the browser. They are examples, not a list of what you need.
About Vynatix
Vynatix is the senior software consultancy for scale-ups. Our engineers join your team, raise the pace and make your software stronger as you grow. Based in Gothenburg, part of Ultra Group.
The Swedish version of this guide is Så inför ni automatiserade mjukvarutester (in Swedish). To see how we work, start with the about page and the cases.
Next step
Let's build tests your team trusts. You will hear from us within one working day.
Tell us what is on your roadmap.
Email us about a projectThe subject line names this guide so we know which page you read (see the privacy notice). Change it if you like.