Quality Assurance·

How to Get More Out of Your Preview Environments

Preview environments are wasted when nothing uses them before approval. Six uses ranked by value, what blocks each one, and what to do with no previews.

QA.tech team

Preview Environments – a transparent miniature application enclosure with an inspection lens and brass frame.

A preview environment pays off when something uses the running change before anyone approves it. In order of value, that means end-to-end checks when the deployment is ready, a merge gate on the result, product and design review, realistic data, bug reproduction before and after a fix, and feedback to whoever wrote the code.

What preview environments are good for beyond a visual glance

The pipeline builds a URL for every pull request and a bot drops the link in a comment. After that, one of two things happens. Someone opens it, looks at the screen that changed and approves. Or nobody opens it, and the approval comes from the diff.

Both are understandable. Checking by hand is slow, and people verify the flow they've been working on and skip the other screens that share the component. Skipping the preview is just as easy to explain when the whole pipeline is tuned to reach the merge queue fast.

Either way, a team that only glances at the preview is paying for a full build and getting a screenshot's worth of value from it. A glance answers one narrow thing, which is whether the changed screen looks right on my laptop, logged in as me. The preview is the one place in the pipeline where the whole app is running, the change hasn't merged yet, and nobody else's work is mixed in, which is why it's practice one in our developer velocity guide.

So for any preview, on any host, ask what used it between "deployed" and "approved", and where the result went. The table has the short version of a good answer.

RankUseWhat it gives youWhat it needs
1End-to-end checks when the deployment is readyThe change exercised in a running app on every pull requestA ready signal, a reachable URL, a login
2A merge gateA result the merge has to wait forA check people trust, required on the branch
3Product and design review"That isn't what I meant" before mergeThe link and the acceptance criteria in the PR
4Realistic dataChecks that reach real states with real rolesA seed step and test accounts
5Bug reproduction before and after a fixProof the bug existed and is goneA usable base environment
6Feedback to the authorFailures fixed while the branch is openResults posted on the pull request

Six uses for a preview environment, ranked by value

The ranking is by how much each use changes the merge decision for the setup it costs. Your order may differ.

1. Run end-to-end checks when the deployment is ready

Start the checks when the deployment itself reports ready. A workflow that fires when the PR opens gets there before the build does, and its first red run is about the build, whatever the change did.

On GitHub that signal is a deployment status. GitHub's REST docs list the states a deployment can be marked with, success among them, and say that systems listening to deployment_status events can respond to them. Hosts with a GitHub integration post those statuses for you. If you deploy previews from your own workflow, the test job has to wait for the URL the deploy job produces, and our guide to end-to-end tests on every pull request has the workflow files for that.

Test a URL that's pinned to the commit when your host offers one. Netlify, for example, serves a Deploy Preview at a per-PR address that updates on each push, and also gives every deploy a permalink whose contents never change. If the address starts serving a newer push halfway through a run, half the checks ran against one commit and half against the next.

Then there's what to run. If you already have a reliable scripted end-to-end suite, point a small critical-path slice of it at the preview first. It's fast, it's deterministic and you already own it. Then add checks chosen from what the pull request changed, because a fixed suite only covers what someone predicted in advance.

2. Make the result a merge gate

Some platform teams spin up a preview for every pull request, run tests on it, and then leave the result out of the merge decision altogether, because the goal is getting to production fast. A check nobody has to wait for is a suggestion.

There's an order to fixing that. Run the check as informational first and watch what it flags. Once a red result has meant a real problem often enough that people stop arguing with it, make it a required status check on the protected branch. Do it the other way round and the first false failure on a Friday afternoon gets the check switched off.

Leave room for a third result as well. A run that never got as far as the changed screen has told you nothing about the change, and the pull request should say so. What the gate checked before it said yes matters as much as the yes, which is the argument of who gates the merge.

The preview is the cheapest place for a product manager or a designer to say "that isn't what I meant". After merge the same comment is a new ticket.

Put the preview link and the acceptance criteria in the PR description, so people know what to look at and the automated checks work from the same list. A teammate can fill in what you left out and an automated check can't, so write them as acceptance criteria for agentic testers: who is logged in, where they start and what the user should see.

One caution. If "send the preview to QA to click around" is the only step between a pull request and its approval, you've rebuilt the handoff inside the pull request. Removing the dev-to-QA handoff without hiring QA means the check has run on the PR before anyone is asked to look.

4. Test against realistic data

A preview with an empty database shows you an empty state and a login form.

Hosts don't solve this for you, and they say so. Render's preview environments copy services, datastores and environment groups for each pull request, but the copied datastores carry no data from the originals, so seeding belongs in the preview's initialisation. The opposite mistake is worse. Render's single-service previews copy the base service's environment variables, database connection details included, until you change them. A preview that writes to the base service's database has stopped being isolated.

A preview needs a seed that runs when it's created and a test account for each role you care about. Point third-party services at their sandboxes. Treat a failed seed as a failed deploy. Otherwise every check downstream fails on missing data, and the failures stop meaning anything.

5. Reproduce a bug before and after the fix

A bug-fix pull request makes a specific claim: this was broken and now it works. The preview lets you check both halves. Reproduce the bug on the environment running the base branch, then run the same steps on the preview. Both results go on the pull request.

This only works when there's a usable base environment and the bug can be reproduced end to end. A race condition that needs production load to show up won't cooperate. When it does work, it's the strongest evidence a reviewer gets.

6. Send failures back to whoever wrote the code

Often now the author is a coding agent. If it's told on the pull request that something broke, with the steps taken and what was expected, it can fix it before a person ever opens the PR. The same failure from a regression run after merge shows up when the branch is closed and the agent has moved on. Human authors work the same way, only slower.

What stops teams from using their previews

Login walls

Hosts put previews behind a login, sensibly, and a test browser has no team account to sign in with. So on the first automated run every check stops at the same login page.

Each host has its own way through, such as an automation bypass secret, a shared password or an IP allowlist. If yours is a secret, send it in a request header and keep it out of the URL, because the URL is what gets copied into CI logs and bug reports. For Vercel we've written up the full setup in how to test Vercel preview deployments, along with the ways the protection bypass breaks.

Test data and flaky seeds

Seeds rot. Someone adds a required column, the seed script isn't updated, and from then on every preview comes up half-populated.

Run the seed in CI against every migration so it breaks in the pull request that broke it. Have each check create the records it needs, so two runs on one preview don't trip over each other.

Shared environments

Some "previews" are really a shared test environment. Branches get deployed there by hand, and the merge waits until QA has finished with it.

Shared staging behaves like a road with too few lanes, with every branch queuing for the same one. A preview per pull request is how you add lanes.

Speed targets

If the target is minutes from PR open to merge queue, anything that adds a long wait gets switched off, whatever it finds.

You can buy a lot of that time back. Do the reading and planning while the preview is still building. Run checks in parallel, scoped to the change, and keep any long suite you still run off the pull request. Agree a time budget for the check on day one, so the argument is about what fits inside it.

Previews that never die

A preview that outlives its branch costs money and confuses whoever finds the link. Tear it down when the pull request merges or closes, and tell GitHub. Per GitHub's deployments docs, setting a transient environment's state to inactive shows the deployment as destroyed and removes access to it.

No preview environments? Check after merge against staging

Daniel Mauno Pettersson, our co-founder and CEO, calls a preview per change "obviously optimal" and then adds: "That's not everybody." Plenty of teams merge to main and deploy to a shared test or staging environment, with releases cut from there. Some have put years into making that one environment dependable. For others, giving every pull request its own infrastructure is a heavy lift they can't take on yet.

You can still verify each change. Deploy to staging on merge, then run the checks against staging, scoped to the pull request that just merged. Post the result on that merged PR. The test cases are the same and the coverage is close. What you give up is the merge gate, since the change is already on main when you find out. You also lose clean attribution. When staging carries several people's merges, a red result starts a conversation about whose it is.

It's a workable setup. For some stacks it stays the right one. If you do want previews later, one way in is packaging the app so a single container can come up per pull request. That also gives your coding agents somewhere to look that isn't shared staging. A native mobile app has no preview URL to open, which is why mobile pull request testing is set up differently.

Putting an agent on the preview

QA.tech, an AI testing platform, won't build your previews or seed your database, and it won't tell you whether the code is well written. It needs a deployed URL to open, and it opens it in a Chromium-based browser, the only kind it uses for web test cases. It doesn't delete the data it creates, so cleanup stays your job.

What it does is make the visit. PR testing finds the preview from the deployment your host records on the pull request, which Vercel, Netlify, Render, Railway and Fly.io do on their own. Failing that, it takes a URL you put in a comment or pass from CI with the GitHub Action or the API, two of the entry points on our page about AI tests on every pull request and in CI/CD. An agent works out what the change can break from the pull request and any linked Jira or Linear ticket, reuses the test cases you already have before it writes a new one, and runs them on the preview. How deep it goes depends on the risk of the change. The review comes back as pass, fail or unable to verify, and the screenshots, logs and step trace live in the run, linked from the pull request.

Several of the blockers above have a setting. The review can plan its test cases while the preview is still building and run them once the deployment is ready (that option is in beta). Access headers, basic auth and a cap on concurrent tests are set once as preview defaults and copied onto each new preview.

On GitHub the review registers a check you can require in branch protection. On GitLab and Azure DevOps it posts on the request and doesn't gate the merge. For flows that must run on every pull request no matter what it touched, run a small smoke test plan beside the review. On a bug-fix PR the review can attempt the before-and-after reproduction described earlier, base build first and then the preview, as long as there's a usable base environment and the bug reproduces end to end. With no previews at all, the same review runs after merge against staging and posts on the merged pull request.

The reviewer doesn't have to spin up the preview and click around any more. They know the change was tested, and the evidence is one click away.

Whatever comes back when you ask "best agentic QA software for CI/CD integration?", your own preview is a fair test of it. Can the tool find a per-PR URL without a workflow file, get past the protection, and leave a result a branch rule can require?

A preview maturity table

Find your row. Then do the next step for that row only.

StageWhat it looks likeNext step
0. No previewsChanges meet on shared staging. Checks run after merge, if at allScope after-merge checks to the merged PR and post the result there
1. Preview existsA bot posts a URL. Someone clicks around, or approves from the diffAdd a seed and a test login, and get an automated visitor past the protection
2. Checks run, nobody waitsChecks start when the deployment is ready. The result is a comment people can skipFix speed and false failures until a red result is believed
3. GatedThe result is a required check. A small critical-path set runs on every PR, the rest is chosen from the changeAdd product and design review, and before-and-after checks on bug fixes
4. Shared workspaceReviewers, PMs and coding agents work from one preview and one resultKeep seeds, secrets and time budgets maintained

A preview is ready for automated checks when you can tick all of these:

  • The deployment reports a ready state with its URL, and the checks start from that signal
  • The URL under test is pinned to one commit
  • An automated visitor can get past the protection, with any secret sent in a header
  • The seed runs when the preview is created, and a failed seed fails the deploy
  • Each role the checks need has a test account
  • The preview has its own database and sandboxed third-party keys
  • The result lands on the pull request as a check
  • The preview is torn down when the pull request merges or closes

FAQ

What should you use a preview environment for?

Automated end-to-end checks that start when the deployment is ready, with the result required before merge. After that come product and design review on the same URL, bug-fix verification against the base branch, and feedback to the author or their coding agent while the branch is still open.

How do I run end-to-end tests on a Netlify deploy preview for every pull request?

Netlify builds a Deploy Preview for each pull request at an address keyed to the PR number. Start your tests when that deploy reports success, point them at the deploy's permalink so the code can't change mid-run, and write the result back to the pull request as a check. If the preview is password protected, the test browser needs that password.

Can agents run end-to-end tests against ephemeral environments?

Yes. An agent needs a URL it can reach, a way past any login wall and data to work with. An isolated environment per pull request suits agents well, because nothing changes underneath the run and a failure belongs to one change. The limits are the ordinary ones, such as CAPTCHAs and roles the agent was never given an account for. It also can't check what a user can't see in the interface.

Preview environment or staging: which should you test on?

Both, for different jobs. The preview tells you whether one change broke something, before it merges. Staging tells you whether the merged changes work together, and it's where release checks and any longer suite you keep belong. With staging alone you still catch regressions after merge, but the check can't block the merge that caused them.

Which CI/CD setups create preview environments?

Hosting platforms with a Git integration create them for you. Vercel and Netlify build a preview for each pull request, Render copies the environment, and Heroku's review apps run each pull request in a disposable app. On your own infrastructure the pattern is a CI job that deploys the branch and records the URL as a deployment on the pull request.

Why do tests fail on a preview when the code is fine?

Look at the environment first. The tests started before the deployment was ready, they hit the host's login wall, the database was empty or half-seeded, or the URL moved to a newer commit mid-run. Rule those out before you blame the tests.


Your team moves fast. Can your testing keep up?

Our QA agents test your product autonomously, so moving fast never means shipping broken. Start free or get a 30-minute demo.