Continuous integration testing: a practical guide
What continuous integration testing is, which tests belong in CI, and how to add browser tests that fail the build. GitHub and GitLab examples.
Continuous integration testing means every push or pull request runs an automated build and a test suite, and a failing test blocks the merge. The phrase is the testing half of continuous integration: people merge often, and the tests decide whether that merge is safe to keep. A pipeline that only compiles the project tells you the code parses. It does not tell you the sign-up form still creates an account.
CI, CI testing, continuous delivery, and continuous testing
These four names get used as if they were one switch. They are four different scopes.
Continuous integration is the habit of merging into the shared branch often, and building on each merge, so two weeks of divergent work does not land at once.
Continuous integration testing is the automated suite on that build. A failed test fails the job. If the project requires a green pipeline before merge, the failure blocks the merge. Without this suite, continuous integration is frequent merging and nothing else.
Continuous delivery starts from a build the tests already passed. Packaging and configuration are automated so a person can release that build. The release decision stays manual. Continuous deployment goes one step further and releases a passing build without that decision. This page is about the tests, not about who clicks release.
Continuous testing is the wider habit of running tests across the lifecycle: on a laptop, in the pipeline, and on a schedule after release. CI testing is the slice that runs because code was pushed.
| Practice | What it covers | When it runs |
|---|---|---|
| Continuous integration | Merging often, and building on each merge | Every push or pull request |
| CI testing | Automated tests on that build. A failure fails the job | Immediately after the build |
| Continuous delivery | Keeping a tested build ready to release | After the tests pass |
| Continuous testing | Feedback across the lifecycle, including CI testing | Locally, in CI, and after release |
Which tests belong in CI
Put the fastest tests first and keep the slowest set small. A pull request that waits an hour gets overridden, and then the suite is decoration.
Unit tests. One function or component, with the network and the database replaced. They should finish in seconds and point at the function that broke. They do not tell you the pages still fit together.
Integration tests. Two or more real parts: a handler and the database, a client and the API it calls. They catch the bugs that appear only at a boundary, and they cost more time than unit tests. They still do not open a browser.
A small set of end-to-end browser checks on the flows that matter if they break: sign up, log in, and checkout or whatever the core action is. Write each one as the outcome, not as a script of selectors. A sign-up check is: open the sign-up page, create an account with a new email and a password the form accepts, and land on the account home with that email visible and no error shown.
That browser set is the top of the suite, not a second copy of every unit test. If it cannot finish in minutes, it is too big for every pull request. Run a wider pass on a schedule, or when the change touches layout, forms, or payment. The pull request should carry the flows a bad deploy would hurt today.
API checks sit next to integration tests when the contract is the thing that breaks. They do not replace the browser check. A 200 from the API and a button that never calls it are both failures, and only one of them shows up in an API test.
Leave performance, security scans, and a large visual suite off the pull request unless the team already reads those results the same day. A red job nobody opens trains people to merge through red.
Adding browser tests to CI
A browser check in CI needs a URL that is already deployed, a description of what should be true, and a job that waits for the verdict and fails when the verdict is failed. Monito runs that check in desktop Chromium. The window is usually 1440×900. The same run does not open Safari, Firefox, or a phone. Those engines need a runner or a device that has them. The Chromium result is a Chromium result.
Scenarios are the checks you want to repeat. You write them in plain English and save them on a Monito project. CI runs the saved scenarios. It does not invent a new tour of the app on each push.
GitHub Actions
The binding is short-lived OIDC. You do not put a long-lived Monito token in the repository. Copying a workflow file into .github/workflows does not create that trust. The CLI has to register the binding.
Sign in with monito auth login and gh auth login. Replace project_123 with the project id:
monito ci plan --execution blocking --auth oidc --project project_123 --json
monito ci apply --execution blocking --auth oidc --project project_123 --yes
monito ci verify --execution blocking --auth oidc --project project_123 --remote-auth --jsonplan prints the workflow and the trust binding for review. apply writes the workflow and registers the binding. verify checks authentication. It does not run tests and it does not spend credits.
The generated job runs:
npx -y @monitodev/cli@4 project run "$PROJECT_ID" --wait --github-summary --github-check --github-commentThe verdict shows up in the job summary and in a Monito check, with links to the evidence. A failure creates or updates a pull request comment. A later pass updates that same comment. The CLI exits 1 when a scenario failed or errored. A GitHub check can stay neutral when the only problems are errors Monito caused, or when collection stops early. A problem reporting to GitHub warns, and it does not change the CLI exit code.
The generated workflow runs on pull requests, on a push to the default branch, and on manual dispatch. It skips fork pull requests. It runs the saved scenarios against their configured environment. It does not deploy your branch. When the job should wait for a preview URL, use the deployment setup and pass that URL. The steps, the workflow, and the limits are on GitHub Actions.
Pull request runs use the workflow from the pull request. Anyone who can push a branch can spend that project's credits. Keep GitHub's setting for write tokens from pull requests off on a bound private or internal repository.
GitLab CI
GitLab uses an API key, not the OIDC binding above. Creating that key requires Pro or Team. Store it as MONITO_TOKEN. Set MONITO_PROJECT_ID to the project id. The check has to run after the review app exists, which is why the example uses the .post stage and needs the deploy job.
monito:
stage: .post
image: node:24
needs: [review]
script:
- test -n "$DYNAMIC_ENVIRONMENT_URL" || { echo "DYNAMIC_ENVIRONMENT_URL is empty"; exit 1; }
- npx -y @monitodev/cli@4 project run "$MONITO_PROJECT_ID" --wait --base-url "$DYNAMIC_ENVIRONMENT_URL"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"The deploy job has to export DYNAMIC_ENVIRONMENT_URL through a dotenv artifact. The guard fails the job when that variable is empty, so the CLI does not quietly test the project's default environment instead of the review app. --base-url replaces the origin and keeps the scenario paths. It does not approve a saved login on a new preview origin.
The CLI waits and exits nonzero when tests failed or errored, which fails the job when allow_failure is off. The browser evidence is on the run report in Monito. Our team has not run this YAML in GitLab. The variable rules, the protected-variable limit, and the sources we checked are on GitLab CI.
What the run keeps, and what it costs
Every pass or fail keeps the evidence from that run: screenshots, console messages, and each network request as method, URL, and status. A run with no login also records a video. A run that signs in keeps masked screenshots instead of a recording. That is the record you open when the job goes red, instead of trying to reproduce a headless failure from a one-line log. The evidence is from Monito's run. It is not a recording of a visitor.
A run ends Passed, Failed, or Error. Passed means the checks in the scenario were observed. Failed means the app did not do what the scenario said. Error means the check could not verify the scenario. An error is not a pass, and it is not by itself a bug in the app. Read the cause before you treat the red job as a product defect. What cannot verify means.
Creating the GitHub Actions binding or the GitLab API key requires Pro or Team. Browser runs use credits. Current prices are on the pricing page. Vercel preview deployments can start the same checks. Netlify Deploy Previews can too: a GitHub Actions job passes the preview URL, or a deploySucceeded function calls the deploy webhook. The Vercel native webhook does not run production deploys, and it does not hold the deployment open for a verdict. Use the CI job when the pipeline has to wait and fail.
Why tests pass locally and fail in CI
The laptop and the CI job are different environments. When they disagree, debug the job. A local pass means the test passed once, on that machine, with that data.
Work through this list before you change the test to match the laptop.
- Environment variables. A key, a callback URL, or a feature flag is set in your shell and missing from the job, or the job has a different value. Print the names the test reads, not the secret values.
- Base URL. You clicked through
localhost. The job opened staging or a preview host. Paths, cookies, and redirects that assume one host fail on the other. - Test data. Your database has the user, the coupon, or the product the test expects. The CI database was migrated empty, or another job deleted the row.
- Timing. CI is often slower, and a wait that was enough locally expires. The reverse happens too: a fast CI click lands before the button is enabled. A fixed sleep hides the race until the machine changes.
- Browser and dependencies. A scripted runner needs the browser installed in the image. A missing system library fails the launch, which looks nothing like an assertion failure. A Monito check does not use the browser in the job image. It uses Monito's Chromium. A failure there is still tied to the URL and the data that environment has.
- Selectors and layout. A selector that matches the first button on your laptop can match a banner at another width or font. Assert the outcome the user would notice, and keep the screen from the failed run.
Flakes belong in this list when the same commit passes and fails with no code change. Quarantine that test, or fix the race. Do not add a retry loop as the fix. Retries spend the time and teach the team that red is temporary.
Keeping CI fast and trusted
A suite people trust is a suite that is fast, small, and red only when something they will fix is wrong.
Run the browser checks on the pull request, against the preview or staging URL that contains the change. The default GitHub workflow does not deploy that URL for you. Wire the preview URL in when the question is "does this branch work," not "does production still match last week's scenarios."
Keep those checks on the critical flows. Sign up, log in, checkout, or the one action the product exists to do. Add the next flow when a real failure escaped, not when a list of pages looks incomplete.
Quarantine a flaky test. Take it out of the required check, write down the race, and put it back when it fails for a reason. A required check that is red every third run will be merged through. After that, a real failure looks the same.
Review the suite when you review the code. A test that nobody can explain is a candidate to delete. So is a test whose failure has been ignored for a week.
Unit tests stay on every commit. The browser set stays small enough to read. Wider browser coverage, including Safari and Firefox, is a separate pass on the engines you claim to support. It does not have to run on every push. How to choose those engines is in how to test a website on different browsers.
FAQ
What is the difference between unit and integration tests?
A unit test checks one function or component with its collaborators replaced. An integration test checks that two or more real parts work together, such as a request handler and the database it calls. Run the unit tests first. They finish in seconds and name the function that broke.
How often should CI tests run?
Run the pipeline on every push and every pull request. Unit and integration tests belong in that run. Keep the browser checks to the critical flows so the pull request still finishes in minutes.
Why do tests pass locally but fail in CI?
The CI job is another machine. Compare environment variables, test data, the base URL, installed browsers, waits, and selectors with the laptop that passed. Debug the CI run. A local pass does not overrule it.
Can UI tests run in CI?
Yes. Run a small set of browser checks on the flows that create an account or take a payment, against the URL the pipeline just deployed, and fail the job when a check fails. A long browser suite on every commit is what makes the pipeline slow enough that people ignore it.
Run a check
Save the scenario, then run it from the pull request with GitHub Actions or from the review app with GitLab CI. Preview deploys are covered on Vercel and Netlify.
Related posts
- Smoke vs sanity testing: new builds and bug fixes
- Manual testing vs automation: a hybrid strategy
- Run the same checks on every deploy