TDD with AI and a CI that distrusts me: how I test Markmedi
About 7,000 Pest test cases, architecture tests, a browser suite in four shards and CI jobs that spin up real MySQL, Redis and Supervisor.
Building a healthcare SaaS alone carries an obvious risk: there is nobody else to notice that today's change broke the health insurance billing I wrote three months ago. Building with AI increases the speed and increases that risk, because the volume of code going through my review has grown a lot. The answer I adopted at Markmedi was to treat tests as the specification and to set up a CI that trusts neither me nor the agent.
The workflow
I use Claude Code day to day, under rules written in the repository itself: conventions for each area, what must never happen to health data, how to name things, which commands to run before considering a task done. The cycle is always the same. First we write the test that describes the behavior, it fails, then comes the minimal implementation and, finally, the refactoring with the tests green.
Writing the test first changes the nature of the review. Instead of reading 400 lines of implementation trying to imagine whether they do the right thing, I read the tests first and ask myself whether that is the behavior I want. If the tests are right and they pass, the implementation still gets a human review, but the question becomes one of clarity and risk, not whether it works. Nothing goes in without me reading the diff.

Pest and the size of the suite
The suite is written in Pest 4, with the Laravel and browser plugins. It is big:
Suite | Files | Written cases | What it covers |
|---|---|---|---|
Unit | 27 | 191 | Pure rules, architecture guards and race condition tests |
Feature | 620 | about 5,900 | HTTP, Actions, jobs, policies and isolation between clinics |
Browser | 141 | about 960 | Real journeys in the browser with Playwright |
That is about 7,000 written cases, and Pest datasets multiply them at run time; the browser suite alone exceeds 1,400 executions. There are also Node frontend tests for the logic that lives in TypeScript.

Most of them are feature tests, and that is on purpose. The value lies in testing an Action or a route with a real database, authorization and events, not in testing isolated classes full of mocks. Mocks are for the boundary with the outside world, and even there the log adapters and the provider fakes reduce the need for them.
Tests that guard the architecture
Some architecture rules are easy to break without noticing, so they became tests that read the source code and fail if they find the forbidden pattern. One of them prevents any file in app/ from generating a file URL with a hand-written disk, because URLs for clinical files must go through the service that generates temporary links. Another guarantees that the CDN domain stays outside the session cookie's scope, so the cookie never ends up in third-party logs.
I also test configuration. The Horizon test checks which queue each job runs on and the chain of timeouts between job, supervisor and connection (details in queues with Laravel Horizon). There is a test for the width of foreign key columns, which only shows up on a real MySQL, and a whole set for isolation between clinics, including attempts to access or delete another clinic's record by id (more in multitenancy and security).
it('rejects a record from another clinic', function () {
$foreign = FinanceEntry::factory()->for(Clinic::factory())->create();
actingAsMemberOf($this->clinic)
->delete(route('finance.entries.destroy', $foreign))
->assertForbidden();
});SQLite where possible, MySQL where needed
The Unit and Feature suites run on in-memory SQLite, with a synchronous queue and broadcasting turned off, which lets thousands of tests run in parallel in a few minutes. But SQLite doesn't reproduce everything: locks across connections, column widths, index behavior, MySQL-specific migrations. For those there are separate CI jobs with the real service, and a concurrency suite that runs against MySQL and forks parallel processes with pcntl_fork (I explained how it works in scheduling concurrency).
The rule is simple: a test runs in the cheapest environment that can still fail for the right reason.
The pipeline
CI runs on GitHub Actions on every push and pull request, split into independent jobs:
Job | What it does |
|---|---|
cache-state | SQLite and MySQL 8 matrix with Redis, testing the cache store switch and behavior during deploys |
queue-state | Real Redis and Supervisor, testing redelivery, graceful shutdown and crash recovery without duplicating effects |
ci | PHP 8.4 and 8.5: frontend tests, asset build and Unit + Feature in parallel |
browser | Browser suite split into 4 shards, with logs and screenshots published on failure |
schema | All migrations from scratch on MySQL 8 and checks for columns SQLite doesn't validate |
The stateful jobs run with --fail-on-skipped and --fail-on-empty-test-suite. Without that, a test that depends on Redis can be silently skipped when the service fails to start, and CI goes green without testing anything. Running on PHP 8.4 and 8.5 warns me of incompatibilities before I upgrade the production version.

A separate workflow handles formatting and linting: Pint for PHP, Prettier and ESLint for the frontend. Another one, triggered manually, builds the production Docker image from an exact commit, with a build context stripped of any environment or credentials file, and publishes the image to the GitHub registry. The deploy itself and the infrastructure are covered in lean, resilient infrastructure.
Browser tests are worth the cost
The browser suite is the slowest and the most expensive to maintain. Even so, it catches what the other tests don't: a button that disappears in the mobile layout, an Inertia page that breaks because the backend stopped sending a prop, a booking flow that works in the feature test and hangs in the JavaScript. The Playwright version is pinned: one upgrade started reading the action timeout from somewhere else, and a click with no target waited forever instead of failing. The version only moves up together with the next Pest migration.
What changed in practice
The gain I feel most is the courage to refactor. Markmedi went through a major frontend rewrite, with pages rebuilt one by one, and the browser tests for the main flows were the safety net for that change. Working with AI also got easier: the agent gets a verifiable target, and I have an objective criterion for rejecting a deliverable.
This post is part of the series about Markmedi. The code organization that makes these tests possible is covered in architecture, DDD and events.