Try agent mode in VS Code!
Dismiss this update
Writing and maintaining tests is a crucial but often time-consuming part of software development. GitHub Copilot streamlines this process by helping you write, debug, and fix tests more efficiently in Visual Studio Code. This article shows you how to leverage Copilot's testing capabilities to improve your testing workflow and increase test coverage in your projects.
Copilot can help with the following testing tasks:
If you don't yet have a Copilot subscription, you can use Copilot for free by signing up for the Copilot Free plan and get a monthly limit of completions and chat interactions.
To accelerate your testing workflow, Copilot can help set up the testing framework and VS Code extensions for your project. Copilot suggests appropriate testing frameworks based on your project type.
/setupTests
command in the chat input field.Copilot can help you write tests for your application code by generating test code that covers your codebase. This includes unit tests, end-to-end tests, and tests for edge cases.
Open your application code file.
Open one of these views:
Enter a prompt like:
Get more guidance about using GitHub Copilot for writing tests in the GitHub documentation.
To generate tests for your application code without writing a prompt, you can use the editor smart actions.
Open your application code file.
Optionally, select the code you want to test.
Right-click and select Copilot > Generate Tests.
Copilot generates test code in an existing test file, or creates a new test file if one doesn't exist.
Optionally, refine the generated tests by providing additional context in the Inline Chat prompt.
Copilot integrates with the Test Explorer in VS Code and can help with fixing failing tests.
Alternatively, you can:
/fixTestFailure
commandAgent mode monitors the test output when running tests, and automatically attempts to fix and rerun failing tests.
If your organization has specific testing requirements, you can customize how Copilot generates tests to ensure they meet your standards. You can personalize how Copilot generates tests by providing custom instructions. For example:
Get more information about personalizing Copilot for generating tests.
To get the best results when generating tests with Copilot, follow these tips: