TLDR overview
- AI software testing uses AI agents to generate and maintain automated tests, which speeds up coverage work that teams used to write by hand.
- Test generation and test execution are separate jobs. The agent writes the tests, and your own test frameworks and CI run them.
- When the same agent writes the code and its tests, the tests can share the code's assumptions, so a green suite with high coverage can still miss a requirement.
- Give AI-written tests an independent source of truth with acceptance criteria written before the work and checks that use a different method than the one that generated the code.
- SonarQube imports the coverage reports your test tools produce and holds new code to your quality gate, and Gitar reviews each pull request in context and diagnoses CI failures.
AI agents can now write and maintain tests quickly, and that speed is useful. An agent can scaffold a test suite, fill coverage gaps, and keep tests current as code changes. For QA engineers, developers, test leads, and platform engineering teams, the open question has moved on from whether AI can produce tests to whether those tests prove what the change needs them to prove. This page explains what AI software testing covers at each level of the test pyramid, why AI-written tests need independent verification, and how to check them, with a worked example.
What is AI software testing?
AI software testing is the use of AI to generate, maintain, and help run automated tests for an application, including unit, integration, regression, and end-to-end tests. An agent reads the code, a specification, or a ticket, writes test cases, and updates those tests as the code changes.
Two separate activities sit inside that definition. Test generation is the agent writing test code, including the assertions, fixtures, and setup. Test execution is your own test frameworks and CI running those tests and reporting pass or fail. An agent can write hundreds of tests that all pass without telling you whether any of them check the behavior the requirement asked for, so keep the two activities distinct when you decide what a green run means.
What can AI test generation cover at each test level?
AI test generation helps at every level of the test pyramid, and each level carries its own blind spot. Matching your expectations to the level keeps the gains real.
Unit tests
Unit tests check a single function or class in isolation. Agents do well here because the scope is small and the inputs and outputs are easy to reason about. Agents also tend to test the behavior the code already has, so a unit test generated from the implementation can confirm a bug as expected behavior.
Integration tests
Integration tests check that components work together, such as a service and its database or two services over an API. An agent can scaffold these when it has accurate context about how the pieces connect. Without that context, the agent guesses at interfaces and writes tests that pass against its own guesses.
Regression tests
Regression tests catch behavior that changes when it should stay the same. Agents help keep a regression suite current as code evolves, which saves real maintenance time. When an agent regenerates a failing test to match new code, though, it can turn a regression into the new expected behavior, so review every change to an existing assertion.
End-to-end tests
End-to-end tests exercise a full user flow through the running application. Agents find these the hardest to generate well, because the tests depend on real user intent, data, and system state. An agent usually produces the happy-path flow readily and can skip the failure and permission paths that matter most.
Why do AI-written tests still need independent verification?
A test proves only as much as the assumption behind it, and when one agent writes both the code and the tests, the code and the tests start from the same assumptions. If the agent misreads a requirement, it writes code that matches its reading and tests that confirm the code, and every test passes while the requirement goes unmet.
Consider an agent that believes an endpoint should return any invoice by ID. The agent writes code that does exactly that and then writes tests confirming that the endpoint returns invoices by ID. The suite is green and coverage looks excellent, yet nobody tested the requirement that users may read only their own invoices, because the agent never treated it as a constraint. Coverage tells you how much code ran during the tests and leaves open whether the tests checked the right things.
Independent verification brings in a source of truth that the generating agent did not produce. Acceptance criteria written before the work starts give you a standard that exists apart from whatever the agent builds. Checks that use a different method than the one that generated the code give you a second opinion that does not share the agent's reasoning. Those checks come in two kinds, deterministic and agentic. Deterministic checks such as automated code review return the same verdict every time they run on the same code, which makes their results repeatable and auditable. Agentic review reasons about intent, business logic, and context that fixed rules cannot express. Each kind catches problems the other misses, so use both, alongside your tests and human approval for high-risk changes.
AI test generation does fairly well on small, simple codebases, where the behavior is easy to reason about and the requirements are few. On large, complex codebases with legacy systems, shared services, and many teams, a plausible test suite can hide a missing requirement for much longer, and independent checks carry more of the load.
How do you combine AI-written tests with automated code review and human review?
Combine them by giving each source of evidence a different job, so that no single source decides whether a change is correct. The generating agent is one of those sources and should never be the only one.
- Write acceptance criteria and failure cases in the ticket or pull request description before the agent starts.
- Let the agent generate tests, then add negative and boundary tests drawn from the criteria.
- Run the tests in your own CI, in an isolated environment with no path to production data or credentials.
- Run deterministic automated code review on the change, including the test code, and import coverage so you can see which new lines the tests exercised.
- Add agentic review of the pull request to check intent, logic, and security-sensitive paths.
- Route changes to authorization, payments, data handling, or infrastructure to a named human approver.
When you write the criteria first, the agent gets context and constraints before it generates anything, which is the Guide part of verification and leaves less to catch later. These steps cover the test-specific part of the job. For the full set of checks a pull request should pass before merge, use the pre-merge AI code verification checklist.
AI-written test verification checklist
Use these questions to judge the quality and independence of the tests an agent wrote. Set your own owners and thresholds based on risk.
- Were the acceptance criteria and failure cases written down before the agent generated the tests?
- Does at least one test trace back to each acceptance criterion?
- Do the tests cover negative paths and boundary cases as well as the happy path?
- Does every permission, ownership, and authorization rule have a test that expects a rejection?
- Did the agent change or delete any existing assertion, and did a person approve each change?
- Does every test contain a meaningful assertion?
- Did a check that uses a different method than the generating agent review the change?
- Is coverage on new code treated as a signal to investigate, with a person confirming the tests check the right behavior?
Worked example: a negative-path test catches a missing ownership check
An agent adds an endpoint, GET /invoices/{id}, and writes tests for it. The acceptance criterion in the ticket says users may read only their own invoices. The agent's test checks that an owner can fetch their own invoice, the suite is green, and coverage on the new code is high.
# Agent-generated test: covers the happy path only
def test_owner_can_fetch_own_invoice(client, owner_token):
response = client.get("/invoices/42", headers={"Authorization": owner_token})
assert response.status_code == 200
assert response.json()["id"] == 42A reviewer then adds a negative test written from the acceptance criterion, in which a different user requests the same invoice.
# Negative test written from the acceptance criterion
def test_other_user_cannot_fetch_invoice(client, other_user_token):
response = client.get("/invoices/42", headers={"Authorization": other_user_token})
assert response.status_code in (403, 404)The new test fails because the endpoint returns the invoice to any authenticated caller. The happy-path suite and its high coverage both missed the absent ownership check. The fix adds the check before the endpoint returns the record.
# Fix: enforce ownership before returning the invoice
@app.get("/invoices/{invoice_id}")
def get_invoice(invoice_id: int, current_user: User = Depends(get_current_user)):
invoice = repo.get(invoice_id)
if invoice is None or invoice.owner_id != current_user.id:
raise HTTPException(status_code=404)
return invoiceAfter the fix, rerun the full suite and every other check on the final commit. Both tests now pass, and the negative test stays in the suite as a regression guard. The negative test caught the flaw because it came from the requirement, which the agent had misread, instead of from the code. Deterministic and agentic review each add a different signal to a change like this one, and neither replaces a test written from the requirement, so run all of them together.
How SonarQube and Gitar support AI software testing
Sonar covers the automated code review, quality gate, and pull request review parts of this workflow. Your test frameworks, test runs, CI pipelines, and human approvers stay in your own toolchain, and SonarQube does not generate or run your tests. In the Sonar State of Code Developer Survey, developers who verify their code with SonarQube were 44% less likely to report experiencing outages due to AI, a survey correlation rather than a guaranteed result.
SonarQube sets the standard. SonarQube Cloud and SonarQube Server import the coverage reports your existing test tools produce when SonarQube runs in your CI pipeline, show coverage on new code so you can see which lines a change left untested, and can fail your quality gate when coverage on new code falls below its threshold (80% in the default Sonar way quality gate). SonarQube also reviews test code with rules written for tests, such as flagging a test that contains no assertions, so the tests that grade your application meet a standard too. A failing quality gate can block the merge when your code host requires the quality gate status on the pull request.
Gitar enforces it at merge speed. Gitar, Sonar's code change verification agent, reviews pull requests in context for logic, intent, and security, and diagnoses CI failures by separating real breakage from flaky tests or infrastructure noise. When your team turns on auto-apply, Gitar commits fixes and iterates until CI passes, sending findings back into the change and re-verifying each fix, which is the Solve part of the CI verification loop. On the Enterprise plan, Functional Validation checks a pull request objective by objective against up to five linked issues and reports any objective the change does not cover, which ties review back to the acceptance criteria you wrote first. Gitar is available on its own or alongside SonarQube.
SonarQube brings deterministic automated code review and Gitar brings agentic review to the pull request, so each change gets both kinds of verification. Both run independently of the agent that wrote the code and its tests, which gives your team a zero-trust, multilayered verification standard at the point of merge.
Sonar Vortex brings verification into the agentic loop. Sonar Vortex works inside supported coding agents and checks each change against the same quality profile that gates merges, so the agent can fix issues in its own code before the pull request opens.
Next steps
- Work through the pre-merge AI code verification checklist to see every check a pull request should pass before merge.
- Read What is zero-trust verification in software delivery? for the model behind this workflow.
- Import test coverage into SonarQube Cloud to see coverage on new code in every pull request.
- Get started with Gitar to add contextual review and CI failure analysis to your pull requests.
