What worked when I used AI to scaffold tests in a healthcare codebase
· 1 min read · #ai #testing #copilot #dotnet
In a regulated healthcare codebase, tests aren't optional, and writing the scaffolding for them is slow. Using GitHub Copilot and ChatGPT to generate unit and integration test stubs cut that time by about 35% for our team. Here's what made it work.
1. Tests still start red
We kept red-green-refactor. The AI drafts the test, a developer reads it, runs it, and confirms it fails for the right reason before any implementation is written. That's how we stayed above 85% coverage with NUnit/xUnit on the backend and Jasmine/Karma on the front end.
2. Give the model the contract, not just the code
The best results came from prompting with the specification: the JSON or XML contract, the validation rules and the edge cases from the user story. Tests generated only from existing code tend to test what the code does, not what it should do.
3. Templates beat one-off prompts
Reusable prompt templates for common shapes (EF Core models, Angular services, API controllers) gave consistent output. The same approach automated about 25% of our boilerplate.
4. A human approves everything
AI-generated code goes through the same code review, security checks and CI pipeline as anything else. The goal is speed without lowering the bar.
AI is a fast junior pair programmer. You still own every line it writes.