# 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.

- **Source:** https://ainativesoftware.engineering/roadmap/day-7/testing-with-ai
- **Site:** AI-Native Software Engineering — https://ainativesoftware.engineering/book

- **Day:** 7 · position 3 of 7
- **Reading time:** 2 minutes
- **Day overview:** [Day 7](https://ainativesoftware.engineering/roadmap/day-7.md)

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.

## 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.

**Theory resources**

- [Playwright MCP Explained: AI-Powered Test Automation in 2026](https://www.testleaf.com/blog/playwright-mcp-ai-test-automation-2026/)
- [The Complete Playwright End-to-End Story, Tools, AI, and Real-World Workflows – Microsoft](https://developer.microsoft.com/blog/the-complete-playwright-end-to-end-story-tools-ai-and-real-world-workflows)
- [BMAD TEA Module – Test Architect for Risk-Based Test Strategy](https://github.com/bmad-code-org/bmad-method-test-architecture-enterprise)

## Practice

Run this in a repository you already know, not a toy project.

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.

- **Previous topic:** [AI as the Bridge Between Design and Development](https://ainativesoftware.engineering/roadmap/day-7/ai-as-the-bridge-between-design-and-development.md)
- **Next topic:** [AI for Documentation](https://ainativesoftware.engineering/roadmap/day-7/ai-for-documentation.md)

---

_AI-Native Software Engineering by Alfonso Graziano (O'Reilly Media, Early Release; print edition February 2027). Every page of ainativesoftware.engineering is also served as Markdown: append `.md` to any URL. Index: https://ainativesoftware.engineering/llms.txt — whole site in one file: https://ainativesoftware.engineering/llms-full.txt._
