You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/test/unit-test-basics.md
+26-20Lines changed: 26 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,21 +79,21 @@ Now that we have some code, it's time for testing.
79
79
::: moniker range="visualstudio"
80
80
## Create unit tests with Copilot
81
81
82
-
Starting in Visual Studio 2026 Insiders build, you can use GitHub Copilot testing for .NET to automatically generate unit tests. For more information, see [Overview of GitHub Copilot testing for .NET](../test/github-copilot-test-dotnet-overview.md). This is the recommended method to generate tests.
82
+
Starting in Visual Studio 2026 Insiders build, you can use GitHub Copilot testing for .NET to automatically generate unit tests. GitHub Copilot testing for .NET not only generates the tests, but debugs the tests, and runs them in Test Explorer. For more information, see [Overview of GitHub Copilot testing for .NET](../test/github-copilot-test-dotnet-overview.md). This is the recommended method to generate tests.
83
83
84
84
Alternatively, you can use Copilot `/tests` slash command to generate unit tests from code. For example, you can type `/tests using NUnit Framework` to generate NUnit tests. For more information, see [Use slash commands in Copilot Chat](../ide/copilot-chat-context.md#slash-commands).
85
85
86
86
### Generate and run unit tests
87
87
88
88
Using the Visual Studio 2026 Insiders build, you can use [GitHub Copilot testing for .NET](../test/unit-testing-with-github-copilot-test-dotnet.md) to automatically generate unit tests.
89
89
90
-
GitHub Copilot testing for .NET not only generates the tests, but debugs the tests, and runs them in Test Explorer. Most of the procedures described in this article apply to manually generated tests. If you want to learn more in-depth information about unit testing, you can read through the rest of this article or skip to the section [Run tests in Test Explorer](#run-tests-in-test-explorer).
90
+
Most of the procedures described in this article apply to manually generated tests. If you want to learn more in-depth information about unit testing, you can read through the rest of this article or skip to the section [Run tests in Test Explorer](#run-tests-in-test-explorer).
91
91
::: moniker-end
92
92
93
-
::: moniker range="<= vs-2022"
93
+
::: moniker range="vs-2022"
94
94
## Create unit tests with Copilot
95
95
96
-
You can also use Copilot `/tests` slash command to generate unit tests from code. For example, you can type `/tests using NUnit Framework` to generate NUnit tests. For more information, see [Use slash commands in Copilot Chat](../ide/copilot-chat-context.md#slash-commands).
96
+
You can use Copilot `/tests` slash command to generate unit tests from code. For example, you can type `/tests using NUnit Framework` to generate NUnit tests. For more information, see [Use slash commands in Copilot Chat](../ide/copilot-chat-context.md#slash-commands).
97
97
98
98
## Create unit test projects and test methods (C#)
99
99
@@ -103,37 +103,43 @@ For C#, it is often quicker to generate the unit test project and unit test stub
103
103
104
104
1. From the code editor window, right-click and choose [**Create Unit Tests**](create-unit-tests-menu.md) from the right-click menu.
105
105
106
-
::: moniker range="vs-2019"
107
-

106
+

108
107
109
108
> [!NOTE]
110
109
> The **Create Unit Tests** menu command is only available for C# code. To use this method with .NET Core or .NET Standard, Visual Studio 2019 or later is required.
111
-
::: moniker-end
112
110
113
-
::: moniker range=">=vs-2022"
114
-

111
+
2. Select **OK** to accept the defaults to create your unit tests, or change the values used to create and name the unit test project and the unit tests. You can select the code that is added by default to the unit test methods.
112
+
113
+

114
+
115
+
3. The unit test stubs are created in a new unit test project for all the methods in the class.
116
+
117
+

118
+
119
+
4. Now jump ahead to learn how to [Write your tests](#write-your-tests) to make your unit test meaningful, and any extra unit tests that you might want to add to thoroughly test your code.
120
+
::: moniker-end
121
+
122
+
::: moniker range="<= vs-2019"
123
+
## Create unit test projects and test methods (C#)
124
+
125
+
For C#, it is often quicker to generate the unit test project and unit test stubs from your code. Or you can choose to create the unit test project and tests manually depending on your requirements. If you want to create unit tests from code with a 3rd party framework you will need one of these extensions installed: [NUnit](https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.TestGeneratorNUnitextension-18371) or [xUnit](https://marketplace.visualstudio.com/items?itemName=YowkoTsai.xUnitnetTestGenerator). If you are not using C#, skip this section and go to [Create the unit test project and unit tests manually](#create-the-unit-test-project-and-unit-tests-manually).
126
+
127
+
### Generate unit test project and unit test stubs
128
+
129
+
1. From the code editor window, right-click and choose [**Create Unit Tests**](create-unit-tests-menu.md) from the right-click menu.
130
+
131
+

115
132
116
133
> [!NOTE]
117
134
> The **Create Unit Tests** menu command is only available for C# code. To use this method with .NET Core or .NET Standard, Visual Studio 2019 or later is required.
118
-
::: moniker-end
119
135
120
136
2. Select **OK** to accept the defaults to create your unit tests, or change the values used to create and name the unit test project and the unit tests. You can select the code that is added by default to the unit test methods.
121
137
122
-
::: moniker range="<=vs-2019"
123
138

124
-
::: moniker-end
125
-
::: moniker range=">=vs-2022"
126
-

127
-
::: moniker-end
128
139
129
140
3. The unit test stubs are created in a new unit test project for all the methods in the class.
130
141
131
-
::: moniker range="vs-2019"
132
142

133
-
::: moniker-end
134
-
::: moniker range=">=vs-2022"
135
-

136
-
::: moniker-end
137
143
138
144
4. Now jump ahead to learn how to [Write your tests](#write-your-tests) to make your unit test meaningful, and any extra unit tests that you might want to add to thoroughly test your code.
0 commit comments