> For the complete documentation index, see [llms.txt](https://learning.contextqa.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learning.contextqa.com/enterprise-application-testing/ship/testing-ai-generated-code.md).

# Test AI-Generated Code Before Merge

Verify AI-generated fixes with a baseline, PR impact analysis, customer-journey tests, regression evidence, and a repeatable human release review.

> **Documentation owner:** [Deep Barot](https://contextqa.com/academy/) · **Last updated:** November 11, 2026

## Quick answer

Test AI-generated code against the same business expectations as human-written code. Establish a baseline, deploy the candidate commit, use Ship to identify affected journeys, run them, and compare the results. Retest every corrective commit. Approve the change only after new failures, existing failures, and incomplete checks have been reviewed.

## Key takeaways

* Compare a known baseline with the exact deployed candidate commit.
* Use impact analysis plus critical journey coverage to choose tests.
* Reverify each corrective commit and classify incomplete results explicitly.

## What you need

* A repository connected to ContextQA, with the intended base branch included in Analysis Settings.
* A reachable base build and PR build, with identifiable commits and comparable test data.
* Reviewed tests for the affected journey and its important dependencies.
* A working auth profile or prerequisite, environment variables, and execution capacity.
* A coding agent or developer responsible for the fix, and a reviewer responsible for the decision.

Use a test environment with synthetic or masked data. For payment examples, use a demo ledger or provider sandbox.

## Step 1: describe the expected behavior before the fix

Write observable assertions that the implementation cannot redefine. For a payment journey, check the entered amount, balance change, transaction history, recipient, and confirmation text. Include decimals, invalid input, cancellation, and authorization where they matter.

If the work starts from a bug, [reproduce it from the ticket](https://learning.contextqa.com/contextqa-mcp/overview/reproduce-bug-from-ticket.md). Record whether it reproduced, did not reproduce under the tested conditions, or could not be determined. A blocked login or unreachable page is not evidence that the bug is absent.

## Step 2: establish the baseline

1. Select the environment for the base build.
2. Confirm its commit or release identifier and the test-data revision.
3. Run the relevant existing suite and retain its results.
4. Classify existing failures and assign an owner to each.
5. Capture the test revisions so later comparisons do not silently compare different assertions.

A baseline with known failures can still be informative, but those failures remain unresolved work. A test that already failed before the PR cannot by itself prove the PR introduced that failure.

## Step 3: deploy the exact candidate

Have the coding agent open a PR after its local checks pass. Deploy that PR's commit to the selected environment. Check the deployment identifier before starting ContextQA execution.

Open **Settings → Analysis Settings** and select the intended test timing and environment. In interfaces using the older label, this page is **PR Impact Analysis**. Check URL preflight warnings: a hardcoded address can keep testing the base deployment even when the environment selection changes.

![Analysis settings with branch scope, test timing, environment selection, and a fixed-URL warning](https://4255556216-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKlyaXxb76z3Dn47TrZkU%2Fuploads%2Fgit-blob-a1982f72952256d1360e62c3416bc849bff41bd7%2Frelease-impact-execution-settings.jpg?alt=media)

*This configuration screenshot shows analysis-only selected. Select the timing that matches your delivery workflow; a screenshot is not a recommendation to leave execution disabled.*

## Step 4: inspect the impact report

1. Open **Autonomous SDLC → Pull requests** and select the PR.
2. Match the analyzed commit to the current PR head.
3. Review scope, changed files, confidence, and evidence for each recommended test.
4. Review suggested additions, updates, and retirements separately from tests that run as-is.
5. Add critical journeys that are missing from the selected scope.
6. If the report is partial or a shared dependency cannot be bounded, expand to the relevant regression suite.

Confidence helps prioritize review; it is not a substitute for execution. For detailed configuration, see [PR impact analysis](https://learning.contextqa.com/enterprise-application-testing/ai-features/pr-impact-analysis.md).

## Step 5: run and compare

Start **Run affected tests** or **Run impacted cases**, depending on the interface label. Open the live run, then wait for its terminal result. Compare the candidate with the baseline using the same test revision and expected behavior.

| Base result | Candidate result                  | Interpretation and next action                                                          |
| ----------- | --------------------------------- | --------------------------------------------------------------------------------------- |
| Pass        | Pass                              | The tested assertion still holds; retain the evidence                                   |
| Pass        | Fail                              | Investigate a possible regression, including data and environment differences           |
| Fail        | Pass                              | Verify that the defect was fixed and assertions were not weakened                       |
| Fail        | Fail                              | Existing failure may remain; inspect whether its cause or severity changed              |
| Any         | Blocked, stopped, or not executed | Incomplete verification; repair the prerequisite or execution issue and rerun           |
| Not run     | Pass or fail                      | New evidence without a baseline; do not infer regression causality from the label alone |

Prerequisite execution can make the number of result rows differ from the number of selected business tests. Reconcile case IDs and dependencies instead of relying only on totals.

## Step 6: return a focused handoff

For a new failure, give the coding agent the candidate commit, test and result IDs, failing assertion, expected and observed values, and relevant screenshots or logs. Ask for a focused correction. Preserve any uncertainty about the suspected code location.

```
The candidate fixes the stored amount, but the confirmation assertion fails.
Expected: the confirmation amount equals the amount submitted.
Observed: the confirmation amount differs by a factor of 100.
Use the attached run evidence and current candidate commit.
Correct the behavior without weakening the assertion.
Run local checks, push the correction, and request fresh journey verification.
```

Do not copy credentials, session cookies, or unredacted headers into the handoff.

## Step 7: verify the new commit and review the release

Repeat impact analysis and execution for the updated head. An earlier passing report does not verify a later patch. Retain the history from base to first candidate to corrected candidate.

The final review should identify the PR, tested commit, deployment, scope, added coverage, new regressions, remaining failures, and reviewer disposition. Use [the release-readiness record](https://learning.contextqa.com/enterprise-application-testing/ship/release-readiness.md#copyable-release-readiness-record).

## Worked example and troubleshooting

The [payments example PR](https://github.com/harshit-sharma44/testing-lab-react-payments/pull/13) separates a stored-amount fix from a confirmation-formatting fix. Apply the same pattern to taxes, inventory, permissions, search filters, and other changes where one screen is only part of the business outcome.

| Symptom                                          | Check                                                              | Resolution                                                                          |
| ------------------------------------------------ | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
| No impact report appears                         | Repository connection, base branch, scope, credits, event delivery | Correct the configuration and retry analysis                                        |
| Tests pass suspiciously quickly                  | Build identity, hardcoded URLs, actual executed count              | Verify the candidate target and run real coverage                                   |
| Many tests fail at login                         | Auth profile, expiration, role, prerequisite                       | Repair sign-in before classifying product defects                                   |
| The agent says fixed but ContextQA cannot verify | Reachability, data, assertion and environment                      | Inspect evidence and resolve the missing prerequisite; keep the result inconclusive |
| Suggested tests exercise nonexistent behavior    | Requirement and generated steps                                    | Reject or edit the candidates and add precise acceptance criteria                   |

## Frequently asked questions

### Can I skip a full regression run?

Use impact analysis for fast feedback, then apply your release policy. Shared services, major upgrades, partial analysis, unknown dependencies, and missing critical coverage justify broader testing.

### Can an AI-generated test validate an AI-generated fix?

Yes, when a reviewer checks the test against independent acceptance criteria. A generated test that merely repeats the implementation's assumptions offers weak protection. Keep business assertions and trusted baseline tests stable during the comparison.

### Does an advisory status check enforce merge policy?

No. Configure actual execution checks and repository protections through your delivery process. Verify that a deliberately failing test prevents progression before relying on the pipeline as a gate.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://learning.contextqa.com/enterprise-application-testing/ship/testing-ai-generated-code.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
