From 981b33338190ff311768ddb7e588891a33423ef3 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:50:05 -0800 Subject: [PATCH] remove outdated article --- .openpublishing.redirection.core.json | 4 + .../core/testing/unit-testing-with-copilot.md | 84 ------------------- .../code-analysis/style-rules/ide3000.md | 1 - docs/navigate/devops-testing/toc.yml | 2 - 4 files changed, 4 insertions(+), 87 deletions(-) delete mode 100644 docs/core/testing/unit-testing-with-copilot.md diff --git a/.openpublishing.redirection.core.json b/.openpublishing.redirection.core.json index d72d8c27a8c73..bfaf313158f1a 100644 --- a/.openpublishing.redirection.core.json +++ b/.openpublishing.redirection.core.json @@ -1227,6 +1227,10 @@ "redirect_url": "/dotnet/core/testing/unit-testing-platform-extensions-vstest-bridge#runsettings-support", "redirect_document_id": true }, + { + "source_path_from_root": "/docs/core/testing/unit-testing-with-copilot.md", + "redirect_url": "/visualstudio/ide/copilot-chat-context#slash-commands" + }, { "source_path_from_root": "/docs/core/tools/cli-msbuild-architecture.md", "redirect_url": "/dotnet/core/tools/dotnet-migrate" diff --git a/docs/core/testing/unit-testing-with-copilot.md b/docs/core/testing/unit-testing-with-copilot.md deleted file mode 100644 index f6c100c90ff54..0000000000000 --- a/docs/core/testing/unit-testing-with-copilot.md +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: Generate Unit Tests with Copilot -author: sigmade -description: How to generate unit tests and test projects in C# using the xUnit framework with the help of Visual Studio commands and GitHub Copilot -ms.date: 01/12/2025 -ms.update-cycle: 180-days -ms.collection: ce-skilling-ai-copilot ---- - -# Generate unit tests with GitHub Copilot - -In this article, you explore how to generate unit tests and test projects in C# using the xUnit framework with the help of Visual Studio commands and GitHub Copilot. Using Visual Studio in combination with GitHub Copilot significantly simplifies the process of generating and writing unit tests. - -## Create a test project - -Imagine that there's a `ProductService` class with a `GetProductById` method that depends on the `IProductDataStorage` and `ICacheClient` interfaces. - -```csharp -public class ProductService( - IProductDataStorage productDataStorage, - ICacheClient cacheClient) -{ - public async Task GetProductById(int productId) - { - var product = await cacheClient.GetProduct(productId); - - if (product is not null) - { - return product; - } - - product = await productDataStorage.GetProduct(productId); - - if (product is not null) - { - await _cacheClient.SetProduct(product); - } - - return product; - } -} -``` - -To generate a test project and a stub method, follow these steps: - -- Select the method. -- Right-click and select **Create Unit Tests**. - -:::image type="content" source="media/create-unit-test.png" lightbox="media/create-unit-test.png" alt-text="Command Create Unit Tests"::: - -In the **Create Unit Tests** dialog, select **xUnit** from the **Test Framework** dropdown menu. - -> [!NOTE] -> The **Create Unit Tests** command defaults to the MSTest framework. However, since this example uses xUnit, you need to install the Visual Studio extension [xUnit.net.TestGenerator2022](https://marketplace.visualstudio.com/items?itemName=YowkoTsai.xunitnettestgenerator2022). - -:::image type="content" source="media/create-unit-test-window.png" lightbox="media/create-unit-test-window.png" alt-text="Create Unit Tests window"::: - -- If you don't have a test project yet, choose **New Test Project** or select an existing one. -- If necessary, specify a template for the namespace, class, and method name, then click **OK**. - -After a few seconds, Visual Studio will pull in the necessary packages, and you'll get a generated xUnit project with the required packages and structure, a reference to the project being tested, and the `ProductServiceTests` class and a stub method. - -:::image type="content" source="media/test-mehod-stub.png" lightbox="media/test-mehod-stub.png" alt-text="Generated stub method"::: - -## Generate the tests themselves - -- Select the method being tested again. -- Right-click and select **Ask Copilot**. -- Enter a simple prompt, such as: - - "Generate unit tests using xunit, nsubstitute and insert the result into #ProductServiceTests file." - - You need to select your test class when you type the `#` character. - -> [!TIP] -> For quick search, it's desirable that `ProductServiceTests` is open in a separate tab. - -:::image type="content" source="media/test-copilot-prompt.png" lightbox="media/test-copilot-prompt.png" alt-text="Prompt for generate tests"::: - -Execute the prompt, click **Accept**, and Copilot generates the test code. After that, it remains to install the necessary packages. - -When the packages are installed, the tests can be run. This example worked on the first try: Copilot knows how to work with NSubstitute, and all dependencies were defined through interfaces. - -:::image type="content" source="media/test-copilot-result.png" lightbox="media/test-copilot-result.png" alt-text="Generated tests"::: diff --git a/docs/fundamentals/code-analysis/style-rules/ide3000.md b/docs/fundamentals/code-analysis/style-rules/ide3000.md index 4b7ff0fb3e377..ef046c4ffa518 100644 --- a/docs/fundamentals/code-analysis/style-rules/ide3000.md +++ b/docs/fundamentals/code-analysis/style-rules/ide3000.md @@ -75,5 +75,4 @@ For more information, see [How to suppress code analysis warnings](../suppress-w ## See also -- [Generate unit tests with GitHub Copilot](../../../core/testing/unit-testing-with-copilot.md) - [Code style rules reference](index.md) diff --git a/docs/navigate/devops-testing/toc.yml b/docs/navigate/devops-testing/toc.yml index 60e8585352339..c32bcee014f3e 100644 --- a/docs/navigate/devops-testing/toc.yml +++ b/docs/navigate/devops-testing/toc.yml @@ -53,8 +53,6 @@ items: - name: Organize a project and test with xUnit href: ../../core/tutorials/testing-with-cli.md displayName: tutorials, cli - - name: Generate unit tests with GitHub Copilot - href: ../../core/testing/unit-testing-with-copilot.md - name: NUnit items: - name: C# unit testing