Add missing tests to pull requests
A test coverage automation checks whether a pull request's change needs new tests. Refactorings, configuration, documentation, and changes the existing tests already cover usually don't. When tests are needed, it writes them the way the project already tests – unit, integration, or both – confirms that they fail without the change and pass with it, and pushes them to the pull request. When they aren't, it comments on the pull request why.
You build it from the Cover PR with Tests template. This topic also shows how to chain it to a code review, so the review sees the pull request with its tests.
Set up the automation
Create a test coverage automation
On the Automations page, click New Automation. In Instructions, click Use Template and select Cover PR with Tests under By Air.
Select the repository, or its environment configuration if the tests need specific tools or services to run.
In Triggers, add with the Ignore drafts filter, and set the change handling to Push to source branch. The tests become a commit on the pull request itself.

Add a second trigger, , also with Push to source branch. A pull request opened as a draft doesn't fire Opened when it becomes ready for review, so without this trigger it never gets tests.
To add tests only when someone asks, use with a label such as
needs-testsinstead.Click Create.
Review the pull request after the tests are in
If a code review automation also starts on , both runs start at once, and the review never sees the tests. Chain them instead: the review starts when the test run finishes, and it gets the test run's summary and links, including the pull request – see Automation chains.
Start the review when the tests are added
Open the code review automation for editing.
In Triggers, delete the pull request triggers – Opened, and also New changes and Moved out of draft if the automation has them. Otherwise the test commit starts a second review, before the test run finishes.
Add an Automation finished trigger, and select the test coverage automation in the Automation field. Keep No code changes.

Add a sentence at the beginning of the instructions, so the agent knows which pull request to review:
Review the pull request linked in the previous run's results.Click Save.
Both automations have to be personal, or both in the same project. A test run that ends with a problem doesn't start the review, so that pull request waits for a person.