Use Copilot to add tests in a .NET repo

The .NET team had Copilot write tests in dotnet/runtime, where it was strongest on test work but sometimes missed older frameworks and CI cases.

Done with GitHub Copilot· Intermediate

What they did
Maintainers in dotnet/runtime handed Copilot coding agent test-writing jobs, including coverage improvements. The agent used coverage tooling, drafted tests, and a maintainer checked each pull request. They also gave it rules for the repo’s test style, such as not asserting exact exception text, using conditional test attributes, and avoiding tests that cannot run on .NET Framework.
How it went
Over ten months, test-related pull requests passed 75.6% of the time, across 99 PRs. The main problems were extra duplicate tests, tests that treated buggy behavior as correct, and failures on older frameworks or in CI.
Tips
Give the agent the repo’s testing rules up front, and ask it to verify the code on every supported framework, not just the latest one. Plan on pruning repeated tests and reviewing CI results, since a local pass may still miss configuration-specific failures.

Try it yourself with GitHub Copilot

In [owner/repo], add or expand tests for [class, method, or feature] using the project’s existing test style. Follow these rules: [list test conventions], avoid asserting exact exception wording, and do not rely on helpers that only work in one framework. First inspect the current coverage and propose the test cases you plan to add. Then write the tests and stop for my approval before you run anything that would submit changes or make irreversible edits. After I approve, check the tests against every supported [framework/version] and report any CI-only failures along with the exact files changed.

Fill in the [brackets]. Agents can make mistakes, so review anything before it is sent, paid or deleted.

Get 3 agent uses like this every morning

With the day's top AI news. Free, and one click to unsubscribe.