Technology & Innovation Software & Applications

Using Claude to Automate Regression Testing: How It Works

A step-by-step guide to automating regression testing with Claude Code and Playwright, including the mutation check that proves a test works.

Laptop showing code and test results on a desk with a coffee mug and notebook
Claude Code works inside the terminal, next to the test runner that does the actual checking.
Table of Contents

Every developer has lived this one. A small change ships, the new feature works, the pull request is approved, and then someone discovers customers can no longer update quantities in their cart.

Using Claude to automate regression testing means letting Claude Code write, run and investigate the tests that catch those breakages, while a real test runner does the checking. This article shows the workflow step by step, with the guardrails that keep them trustworthy.

You will get a complete Playwright example, a second pattern for API tests, the rules file that stops Claude from cutting corners, and the check that proves a test can catch a bug.

Key Takeaways

  • Claude Code writes and investigates regression tests, while Playwright or another runner executes them.
  • Write the expected behaviour before asking Claude to generate code, or it may copy an existing bug.
  • Put your testing rules in CLAUDE.md so every session follows the same standards.
  • Prove each test works by deliberately breaking the feature and confirming the test fails.
  • Review AI-generated tests like generated code: 30% of developers report little or no trust in AI-generated code, per Google’s DORA research.

What does using Claude to automate regression testing mean?

Using Claude to automate regression testing means using Claude Code, Anthropic’s terminal-based coding agent, to generate regression tests from your codebase, run them through a test runner such as Playwright, and investigate the failures. Claude inspects routes, reads existing tests, writes new test files and runs terminal commands, but the runner, not Claude, decides whether each test passes or fails.

Regression testing catches failures where a change breaks something your application already did correctly. The automation part is the writing, running and summarising.

The important limit is that Claude is not a source of truth. It can misunderstand a business rule, invent a route that does not exist, or write an assertion that passes no matter what the application does.

The workflow in seven steps

The steps below follow the pattern in the Medium guide by Michael Brown, combined with Anthropic’s own quickstart.

  1. Choose one business flow worth protecting.
  2. Set up Claude Code and Playwright.
  3. Give Claude explicit testing rules in CLAUDE.md.
  4. Generate one test and review it.
  5. Run the test and investigate.
  6. Check the test can catch a regression.
  7. Add it to CI and measure the workflow.

Step 1: Choose one business flow worth protecting

Start with a journey where a failure would matter: signing in, completing a purchase, updating a subscription, or saving a customer record. The worked example here is a shopping cart: a customer adds a product, changes its quantity from one to two, and the total updates and persists after a reload.

Write the expected behaviour before asking Claude to generate code. Otherwise, it may reproduce the application’s current behaviour, including an existing bug. Use a dedicated test environment with predictable data: a seeded $25 product, an empty cart, and no taxes or discounts.

Step 2: Set up Claude Code and Playwright

Install Claude Code using the Claude Code quickstart from Anthropic. You need a terminal, a code project, and a way to sign in: a Claude subscription, a Claude Console account, or a supported cloud provider. Then launch it with the claude command.

If the project does not already use Playwright, initialise it with npm init playwright@latest, choose TypeScript, and install the browser binaries when prompted.

Before generating tests, give Claude a focused instruction: inspect the repository’s routes, cart implementation, existing tests and test-data setup, then propose a regression test for updating cart quantity, and identify missing information and assumptions before writing code. Do not change application code.

Step 3: Give Claude explicit testing rules

Generated tests deserve the same review as generated application code. Stack Overflow’s 2025 Developer Survey found that 46% of respondents distrusted AI-tool accuracy, compared with 33% who trusted it.

Add project-specific rules to your CLAUDE.md file so every session follows them. The table below shows the rules from the Medium guide and what each one prevents.

Rule in CLAUDE.mdWhat it prevents
Use Playwright Test and TypeScriptMixed frameworks and test style
Prefer getByRole, getByLabel or test IDsBrittle selectors that break on UI changes
Use retrying assertions, not fixed sleepsFlaky timing failures
Keep tests independent with predictable dataTests that depend on run order
Verify business outcomes, not clicksTests that pass while the feature is broken
Do not weaken assertions or change app code to passTests that hide real defects

Claude Code’s documentation recommends supplying context Claude cannot infer from code and giving it concrete checks to run. Playwright’s best practices recommend user-facing locators and assertions that wait.

Step 4: Generate one test and review its assertions

Now give Claude the expected result in plain words: implement the cart regression test using the repository’s actual routes and locators, use the seeded $25 product and an empty cart, change quantity to two, verify a $50 total, reload, and verify both values.

An illustrative test looks like this: go to the product page, add the item to the cart, open the cart, set the quantity to two, check the total reads $50.00, reload, and check both values again. The routes, labels and test ID are placeholders to adapt to your application.

Notice what the test checks: the amount is correct and the change persists. A test that only checks whether the update button can be clicked would miss both failures.

Step 5: Run the test and investigate failures

Start the application, then run the test with the headed flag so you can watch it: npx playwright test tests/cart.spec.ts --headed. For useful failure evidence, keep retries, an HTML reporter, trace capture on failure and screenshots on failure in your Playwright configuration.

When a test fails, ask Claude to run it, inspect the failure output and artifacts, and determine whether the cause is an application defect, incorrect test logic, test data, or environment setup. Ask it to explain the evidence first.

A successful retry still needs attention. A test that fails initially and passes on retry is classified as flaky, and flaky tests erode trust in the whole suite.

Step 6: Check that the test can catch a regression

A passing test proves little if it would also pass when the feature is broken. This is the step most teams skip.

Terminal window showing a row of green passing test results
A green test run only means something if the same test turns red when the feature breaks.

On a temporary local branch, deliberately introduce a small defect, for example by stopping the application from saving the updated quantity. Run the test, confirm it fails, then revert the defect.

This verifies that the test is sensitive to the behaviour it claims to protect. If the test still passes with the defect in place, the assertion is checking the wrong thing.

Step 7: Add it to CI and measure the whole workflow

Playwright’s initialiser can generate a GitHub Actions workflow: npm ci, npx playwright install --with-deps and npx playwright test. CI also needs a running application, prepared test data and credentials, so configure application startup through Playwright’s webServer option and retain reports for failed runs.

Run critical journeys on pull requests, and expand browser coverage as the suite grows. Track time spent writing, reviewing, debugging, and maintaining tests, not just how quickly Claude generates them.

The useful outcome is a set of tests your team can trust when the product changes. Start with one important journey, prove the test catches a real failure, and build from there.

The second pattern: API regression with Claude Skills

Browser tests are only half the story. Many teams also have API tests that are hard to use, because nobody remembers which scenario to run, which command to type, or how to switch environments.

The DEV Community guide by Takuya Nakamura shows a different pattern: Apidog holds the test scenarios and suites, and Claude Code drives them through a Claude Skill. You type one natural-language sentence, asking Claude to run the happy-path scenario and summarise pass rate, failed cases, estimated cause and suggested fixes.

Claude matches the request with the skill, identifies the test, executes the Apidog CLI, and summarises the output. The skill is a small directory in the repository, usually .claude/skills/apidog-tests/, holding a SKILL.md file with trigger conditions and the execution flow, plus environment details and per-test command files.

The advantage is that the execution flow becomes a version-controlled, reviewable project asset. Team members do not need to remember commands or scenario IDs. Tokens and scenario IDs live in environment variables.

This pattern fits API automation testing, regression testing and daily development flow, and it extends to multi-environment comparison and automatic regression before commits or merges. For the full walkthrough, see the API regression testing guide on DEV Community, and the Claude Code and Playwright guide on Medium.

What Claude should never do unsupervised

Claude is a strong assistant and a poor authority. Google’s 2025 DORA research explains why: 90% used AI at work, more than 80% believed it improved productivity, yet 30% reported little or no trust in AI-generated code.

  • Never let Claude weaken an assertion to make a failing test pass.
  • Never let Claude change application code to satisfy a test.
  • Never accept a test without reading its assertions.
  • Never run generated tests against production data.
  • Never let Claude pick the business rule. You write the expected behaviour.
  • Never trust a green run that has never been proven to turn red.

There is a wider reason for caution. Research on AI agents has shown that agents can learn to game tests, so a test suite that Claude both writes and passes deserves extra scrutiny. Our report on AI agents cheating tests covers that risk in detail.

For API work, the design of the system under test matters as much as the tests. Our guide to API-first design principles explains how to build testable services.

How to tell whether it is working

Speed of generation is the wrong metric: a test written in thirty seconds that nobody trusts is worth less than one written in thirty minutes that catches real bugs.

Track the whole workflow time, including review, debugging and maintenance. Track the flaky rate, because a suite that cries wolf gets ignored.

Frequently Asked Questions

Can Claude write regression tests by itself?

Claude Code can generate regression tests from your codebase, but it should not work alone. You write the expected behaviour first, Claude writes the test, and you review every assertion before trusting it, because a test that copies a bug will pass while the feature stays broken.

Do I need Playwright to use Claude for regression testing?

No. Playwright fits browser and UI flows best, but API tests work better with a CLI runner such as Apidog driven through a Claude Skill. Choose the runner that matches the layer you are testing.

What is a Claude Skill?

A Claude Skill is a small directory in your repository, usually under .claude/skills/, that teaches Claude an executable flow: when to trigger it, which commands to run, and how to summarise the result. The skill lives in version control with the code, so the whole team runs the same flow.

How do I stop AI tests from passing when the feature is broken?

Run a mutation check: deliberately break the feature on a temporary branch, confirm the test fails, then revert the change. If the test still passes with the defect in place, its assertions are checking the wrong thing.

One Flow, One Proven Test, Then Scale

The fastest way to fail at using Claude to automate regression testing is to generate fifty tests in an afternoon and trust none of them. The reliable way is slower: pick one flow that matters, write the expected behaviour first, set the rules in CLAUDE.md, generate one test, and prove it turns red when the feature breaks.

Do that once, and you have a pattern your team can repeat. Do it ten times, and you have a suite worth trusting.

David Chen
Senior Technology Analyst

David Chen

David Chen is a senior technology analyst who explains complex systems in plain language. A former software engineer, he covers artificial intelligence, semiconductors and the innovations reshaping the tech industry.

View Full Author Profile →
Keep Reading

Related Stories

More in Technology & Innovation →