> ## Documentation Index
> Fetch the complete documentation index at: https://momentic.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PR testing

> Run your tests automatically on every pull request.

PR testing runs your Momentic tests on every pull request, so a change runs
against a real browser or emulator before anyone approves it. Reach for it to
catch behavior that reading the diff cannot show: a broken flow, a missing
state, a regression in code the diff did not touch.

Run the tests against the PR's preview deployment and emit a JUnit report for
your CI:

```bash theme={null}
npx momentic run --url-override "$PREVIEW_URL" --reporter junit
```

## When to use it

* You review code by reading diffs and want a runtime signal next to them.
* You want failures attributed to the change that introduced them, while the
  author still has context, instead of discovering them days later on `main`.
* You want new code to arrive with coverage instead of relying on someone
  remembering to add a test.

This is most valuable once you have per-branch preview deployments. Without one,
you can still run against a shared staging environment, but a failure is harder
to attribute to a single PR.

## Where it fits in review

* Run the tests as a required check on the pull request branch so a failing run
  blocks the merge, the same way unit tests or linting do.
* Run against the branch's preview deployment so you exercise the code in the
  PR, not production. For protected previews, see
  [Vercel preview auth](/guides/auth/vercel-previews).
* A passing run is evidence the change works; a failing run is a reproduction
  with a trace you can open, not just a comment thread.

## Cover what the PR changed

A static test suite only catches regressions in flows you already test. Use the
[explore agent](/ai/explore) to read the diff, find the user journeys it
changed, and draft tests for the ones you do not cover yet.

```bash theme={null}
# In CI, the diff window defaults to the pull request
npx momentic ai explore diff
```

By default it opens the drafted tests as a pull request you review before they
merge; pass `--dry-run` to only discover and log the changed journeys instead.

## Get started

<Steps>
  <Step title="Add Momentic to CI">
    Run the tests in your CI pipeline on pull requests. Store your
    `MOMENTIC_API_KEY` as a CI secret. See [GitHub
    Actions](/running-tests/ci/github-actions), [GitLab
    CI](/running-tests/ci/gitlab-ci), or [custom
    setups](/running-tests/ci/custom-setups).
  </Step>

  <Step title="Point tests at the PR's preview">
    Set the base URL to the branch's preview deployment so each run tests the
    proposed change, not production.
  </Step>

  <Step title="Cover new journeys">
    Run [`momentic ai explore`](/ai/explore) against the diff to find changed
    journeys, and add tests for the ones not yet covered.
  </Step>
</Steps>

## Keep PR feedback fast and trustworthy

* Shard large test suites across CI jobs with `--shard-count` and
  `--shard-index` so a PR is not blocked waiting on a serial run.
* Decide a flake policy up front. Quarantined tests run but do not fail the PR
  by default; pass `--skip-quarantined` to skip them, or `--ignore-quarantine`
  to make every status count. See [quarantine](/reliability/quarantine).
* The base URL set on a test takes precedence over `--url-override`; leave it
  unset on tests you want to retarget per environment.

## Related

<CardGroup cols={2}>
  <Card title="Explore agent" icon="compass" href="/ai/explore">
    Find the journeys a diff changed and author tests for them.
  </Card>

  <Card title="GitHub Actions" icon="github" href="/running-tests/ci/github-actions">
    Run Momentic on pull requests, with sharding and secrets.
  </Card>

  <Card title="Regression testing" icon="shield" href="/guides/use-cases/regression-testing">
    Protect existing flows across every change.
  </Card>

  <Card title="Vercel preview auth" icon="lock" href="/guides/auth/vercel-previews">
    Test against protected preview deployments.
  </Card>
</CardGroup>
