Technical document

AI Agent Development Supported by Playwright E2E + Vitest

Testing strategy in an era where AI writes most of the code. We explain the allocation based on E2E, test data independence, TDD order to prevent status quo confirmation tests, and CI design.
Testing / AI Dev~13 minPublication Date September 22, 2026Update date September 22, 2026
AI Agent Development Supported by Playwright E2E + Vitest

Summary

Key points of this document

  • Reinterpreting the Test Pyramid.
  • With Playwright, we start writing tests for "operations that would halt the business."
  • Place unit tests where complexity is concentrated.

Overview

When AI agents write most of the code, the role of testing changes. Traditional tests are for "finding mistakes in code you wrote." Tests in the AI era are "evidence to trust code you didn't write." We explain how Vitest and Playwright are used at flares.jp.

Reinterpreting the Test Pyramid.

The traditional test pyramid teaches "thick unit tests, thin E2E tests." However, assuming AI agents write the implementation, it's worth re-evaluating this distribution.

There are two reasons. First, the cost of creating E2E tests has dramatically decreased. Playwright test code is boilerplate and the kind of code AI agents excel at. The biggest reason for traditionally keeping E2E thin, "expensive to write and maintain," is no longer valid. Second, E2E has the strongest detection capability against how AI makes mistakes. Typical AI failures are when individual functions are correct but break when combined, or when requirements are subtly misunderstood. Only E2E tests, which directly verify user operation flows, answer the question "Does it actually work?"

Therefore, we consider the order of "first solidifying E2E for critical paths, then adding unit tests to complex logic parts."

With Playwright, we start writing tests for "operations that would halt the business."

In business applications like LMS, we select E2E test targets in order of business impact. Our priorities are login authentication, student course enrollment flow, administrator's student invitation, and progress report display. If these four pass, the core of the service is alive.

There are three key points in implementation. Test data independence (most E2E instability comes from data sharing. Each test creates its own data and cleans it up). Selector discipline (use getByRole, getByLabel as primary, and data-testid only where necessary. This aligns with accessibility improvements, killing two birds with one stone). Utilizing screenshots (incorporating a step for AI agents to "take a screenshot of the changed screen and verify it" reduces incidents of submitting PRs without noticing layout breaks).

  • Test seeders should be callable via API endpoints and excluded from production builds.
  • Avoid selecting elements by CSS classes; instead, select them by user-visible text and roles.
  • Keep screenshots of main screens as CI artifacts.

Place unit tests where complexity is concentrated.

Unit tests are not meant to cover everything, but to be placed where complexity is concentrated. Specifically, this includes calculation logic for dates and progress rates, string processing for Japanese and Vietnamese, form validation rules, and API response transformation processing.

The most important caution when having AI write unit tests is not to have it write tests simultaneously with the implementation. If you ask an agent to write tests immediately after implementation, it tends to create "status quo confirmation tests" that merely copy the implementation's behavior. This offers no protection if the implementation is wrong from the start.

We adopt the principle of "have tests written from requirements," and where possible, we enforce the TDD order on the agent: write tests first, then implement. If tests are a translation of requirements, implementation can be entrusted with confidence.

CI is divided into two layers, aiming for PR checks to complete within 5 minutes.

In monorepo CI, path filters that test only changed applications are fundamental. On top of that, during PRs, only linting, type checking, unit tests, and critical path E2E are run. The full E2E suite is executed after merge and before deployment.

Not running everything during PRs is because feedback speed directly impacts AI agent work efficiency. Agents self-correct based on CI results, but if there's a 20-minute wait, the overall session efficiency drops significantly.

Tests become the "specification document."

Test code is the most reliable specification document for AI agents. Showing specifications through test code is less ambiguous than writing them in prose. Agents learn "this is the correct behavior for this app" by reading existing tests. The quality of tests directly reflects the quality of the agent's output.

The era when humans don't write code is the era when humans write requirements in the form of tests.

For existing projects, start by adding E2E tests for critical paths.

We show a realistic order for introducing tests to existing projects with thin test coverage. The first step is 4 E2E tests for critical paths. Without touching existing code, fix the current correct behavior as tests. The second step is integration into CI. Tests that only run locally will inevitably rot. The third step is applying TDD from new features.

The command "write tests for everything" will fail. The way to sustain it is to increase tests in order of importance and as opportunities arise.

  • Unstable tests are more harmful than no tests. Fix them by thoroughly ensuring data independence and replacing with automatic waits, and remove them from the suite until fixed.
  • Instruct AI in two stages: "List requirements as bullet points" → "Write tests to verify each requirement."
  • Do not set numerical coverage targets. Use it as a tool to find untested areas.

Technical documents

We will continue to increase technical documentation.

We will continue to organize our thoughts on AI, cloud, business app development, requirements definition, and operational design into documents.

Go to technical documentation list