Skip to content
Latchkey

What Is a Visual Regression Test? Catching Unintended UI Changes

A visual regression test captures a screenshot of the UI and compares it pixel-by-pixel to an approved baseline, flagging any unexpected visual change.

Functional tests confirm behavior but miss visual breakage: a misaligned button or a wrong color still passes a click test. A visual regression test renders the UI, screenshots it, and diffs it against a baseline image. Any difference is surfaced for review. Because screenshots are sensitive to environment, running these reliably is largely a CI consistency problem.

How it works

The test renders a component or page, captures a screenshot, and compares it to a stored baseline. If pixels differ beyond a threshold, the test fails and shows the diff so a human can approve or reject the change.

Baselines and approval

The baseline is the agreed-upon correct appearance. When a change is intentional, you update the baseline; when it is not, you fix the code. Managing baselines is the core workflow of visual testing.

The flakiness challenge

  • Font rendering differs across operating systems.
  • Animations and timing cause unstable captures.
  • Dynamic data like dates shifts the image.

Pairing with Storybook

Stories are deterministic component states, which makes them ideal inputs for visual tests. Many teams snapshot every story so each component state has a guarded baseline.

Visual regression tests in CI/CD

These tests run in the pipeline against a built app or Storybook, so consistency is everything: differing fonts or screen sizes between local and CI produce false diffs. Running captures on stable, identical runners keeps baselines trustworthy. Managed runners (like Latchkey) provide that consistent environment so screenshot diffs reflect real changes, not runner noise.

Key takeaways

  • A visual regression test diffs UI screenshots against an approved baseline.
  • Baseline management is the core workflow; intentional changes update the baseline.
  • Consistent CI runners are essential to avoid false diffs from rendering differences.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →