AI for Developers · Concept
Testing and Debugging with AI
Use AI to propose tests and explain failures while keeping observations and verification in the developer's hands.
On this page
A starting question
Your checkout page sometimes shows an empty cart after you add an item. An assistant says it is a “race condition” and writes a test. How do you know that diagnosis is right?
You reproduce the failure, inspect the evidence, and run a test that captures the intended behavior. The AI explanation is a hypothesis—a possible cause—not a measurement. GitHub warns that AI review and code suggestions can be wrong even when they sound convincing.Verify the particular claim against the running application.1
Mental model
Three useful test scopes
A unit test checks a small piece of logic, such as a function that calculates a total. An integration test checks pieces working together, such as a route and its data-access layer. An end-to-end test follows a user flow through the running application, such as adding an item and seeing it in the cart. Boundaries vary by project; these labels describe scope, not a ranking of importance. Browser tools such as Playwright support end-to-end checks.A browser check can reveal wiring problems that a small unit test never reaches.2
For the cart bug, a unit test might confirm the cart-total calculation, while an end-to-end test may expose that the UI never applied the latest response. One does not substitute for the other.
Use AI for suggestions, not verdicts
Give the assistant the observed behavior, expected behavior, relevant code, and a failing test or error message. Ask for possible causes and the next discriminating check. A useful suggestion might be, “Log the request ID and compare the order in which responses finish.” A poor suggestion is, “Rewrite the cart state layer” before the failure boundary is known.
When AI drafts a test, read its assertions. Does it check the behavior users need, or merely repeat the implementation? Would the test fail if the bug returned? Run it and deliberately inspect a failing version where practical. Automated checks can also run in CI, a system that builds and tests proposed changes before integration; GitHub’s testing documentation describes that role.CI reports the checks that ran, not all possible behavior.3
When the error explanation sounds certain
An error message often describes where a failure surfaced, not where it began. If an API request fails, check whether the browser sent it, whether the server received it, and what response returned. AI may help translate the stack trace, but your logs, network panel, and reproducible steps are stronger evidence.
Recap and try it
Use AI to generate hypotheses and test ideas. Keep the feedback loop grounded in observed behavior and checks that would catch the original bug.
Reflect, then reveal each answer.
An AI-written test passes, but the cart still empties in the browser. What does that tell you?
The passing test does not cover the failing behavior or its full boundary. Reproduce the browser flow, inspect the request and state updates, then add a test that fails for the actual bug.
How this connects
- Reliable Software Workflows
Later: place reviewed tests in a repeatable team delivery process.
- The JavaScript Runtime, Event Loop, and Async Code
Review response order and asynchronous UI behavior in the frontend path.
References & further reading
References & further reading3 sourcesPrimary standards and official documentation used for this lesson.
- Application card: GitHub Copilot Agents (opens in a new tab)
GitHub Docs
Why AI-generated fixes and review comments require verification
- Installation (opens in a new tab)
Playwright
End-to-end browser testing as one kind of automated check
- Building and testing your code (opens in a new tab)
GitHub Docs
Automated build and test checks in continuous integration