หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Make sure that your code is working as expected by creating and running unit tests using GitHub Copilot testing for .NET.
Although Copilot can generate unit tests, you get extra testing capability by using GitHub Copilot testing for .NET in Visual Studio, including the following:
- Unit tests are generated in a separate project within the solution.
- Copilot generates tests deterministically, grounded in the C# compiler and language semantics, so assertions and edge cases are predictable and type-safe.
- GitHub Copilot testing builds the unit tests following test generation. If there are errors, the unit testing capability in GitHub Copilot for .NET tries to identify and fix errors, and then re-runs the tests.
- GitHub Copilot testing runs the tests using Test Explorer.
GitHub Copilot testing for .NET generates tests for C# projects only using the MSTest, NUnit, and xUnit frameworks.
Prerequisites
To get started, you need:
- Visual Studio 2026 Insiders build
- Sign in to Visual Studio using a GitHub account with Copilot access
Tip
For the best experience, we suggest using a paid Copilot subscription to avoid potential throttling and ensure consistent access.
For an introduction to unit testing, see Unit test basics.
Generate and run tests
Open an existing C# project that needs new tests.
If you don't have an existing project, you can create a new project and then use the Bank sample application code to experiment with unit testing. Copy the starting sample code from Create and run unit tests for .NET into
Program.cs.Build the project.
Make sure the project builds without errors to simplify the process.
In Visual Studio, select View > GitHub Copilot Chat.
Use the following syntax in the Chat window to start GitHub Copilot testing and generate tests:
@test #targetwhere
#targetcan be the name of a solution, project, file, class, or member.For the Bank sample code, you can specify the class name:
@test #BankAccount. The Test command appears in the chat as follows, indicating that the command is recognized.
In the Chat window, select Send.
GitHub Copilot testing for .NET initiates an iterative process of analyzing your code, creating a new project for the unit tests, generating tests, building, and running the tests.
Test generation is a long-running process. Depending on the scope of your target (file, project, solution, etc.) it may take a while.

When unit tests are generated, the tests appear in a separate test project in the solution.

Test Explorer shows the results. If Test Explorer is not automatically opened by GitHub Copilot testing, select Test > Test Explorer.

At this point, you can manually use Test Explorer to continue running tests, or chat with Copilot about the test results. You can also use Copilot to debug failed tests. For more information, see Debug unit tests.