Skip to content

Testing with AI

How to use AI agents to write, run, and maintain tests, from unit tests to end-to-end browser flows. Covers AI-generated test cases, Playwright MCP for browser automation, and the BMAD TEA module for risk-based test strategy and release gates.

  • 2 min read
  • Theory and practice
  • Day 7 of 7

Theory

AI has changed testing at every level. For unit tests, tools like GitHub Copilot can generate tests for a whole class or file in seconds, then automatically run them and fix failures. For end-to-end tests, Playwright MCP lets an AI agent connect to a live browser session and interact with your app the same way a human would: clicking, typing, reading the DOM. The agent can generate test scripts from natural language, fix broken selectors when the UI changes, and even verify that a feature it just built actually works in the browser.

The TDD loop with AI is simple: you describe a behavior, the AI writes a failing test, then writes the code to make it pass, then runs it to confirm. Tools like GitHub Copilot Testing and BMAD TEA go further, adding risk-based prioritization so you know which tests matter most before a release. TEA can trace requirements to test coverage, assess non-functional risks, and give a clear go/no-go decision. The result is a testing workflow where AI handles the repetitive parts and you stay focused on what to test and why.

Practice

Run this in a repository you already know, not a toy project. The point is to feel where the practice helps and where it gets in the way on code that has history.

Pick any small web app you have locally (or clone a simple one). Then:

  1. Install the Playwright VS Code extension and run npm init playwright@latest to scaffold your test setup.
  2. Add the Playwright MCP server to your AI agent (Claude, Copilot, or Cursor). With GitHub Copilot in VS Code it is already built in.
  3. Open a chat with your AI agent and write: "Open my app at localhost:3000, explore the main user flow, and generate Playwright tests for the most critical path."
  4. Let the agent browse your app, inspect the DOM, and write the test file.
  5. Run the generated tests with npx playwright test. Check the HTML report with npx playwright show-report.
  6. If any test fails, open the Trace Viewer, click "Copy as Prompt", and ask the AI to fix the issue.

By the end you should have at least one working E2E test generated almost entirely by an AI agent, and you will have seen the full loop: describe intent, AI browses, AI writes tests, AI fixes failures.

The rest of day 7

  1. 01AI in Requirements and Product Collaboration
  2. 02AI as the Bridge Between Design and Development
  3. 03Testing with AIYou are here
  4. 04AI for Documentation
  5. 05Continuous AI: AI in Your CI/CD Pipeline
  6. 06AI for Debugging and Incident Response
  7. 07AI for Your Custom Workflows in the SDLC
Where this comes from

This path is the shortest route to the ideas. AI-Native Software Engineering (O'Reilly Media) is where each one is worked out in full, with the patterns, the trade-offs and the failure modes. The pillars cover the foundations one long essay at a time.