Skip to content

Commit 3e172e5

Browse files
Merge pull request #13938 from Mikejo5000/mikejo-br26
Update article on test-driven development
2 parents 9f1d8ba + 8ef5323 commit 3e172e5

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
60.9 KB
Loading

docs/test/quick-start-test-driven-development-with-test-explorer.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Test-driven development walkthrough
33
description: Learn how to develop a tested method in C# using Microsoft Test Framework, which you can easily adapt for other languages or test frameworks, such as NUnit.
4-
ms.date: 12/04/2023
4+
ms.date: 5/16/2025
55
ms.topic: conceptual
66
ms.author: mikejo
77
manager: mijacobs
@@ -18,7 +18,7 @@ This walkthrough demonstrates how to develop a tested method in C# using Microso
1818

1919
1. Create a C# **Class Library** project for .NET or .NET Standard. This project will contain the code that we want to test. Name the project **MyMath**.
2020

21-
2. In the same solution, add a new MSTest test project for .NET.
21+
2. In the same solution, add a new **MSTest** test project for .NET.
2222

2323
In Visual Studio 2019 version 16.9, the MSTest project template name is **Unit Test Project**.
2424

@@ -31,7 +31,7 @@ This walkthrough demonstrates how to develop a tested method in C# using Microso
3131
![New code and test projects](../test/media/test-driven-development-ide.png)
3232
::: moniker-end
3333

34-
3. Write a simple test method that verifies the result obtained for a specific input. Add the following code to the `UnitTest1` class:
34+
3. In the test project, write a simple test method that verifies the result obtained for a specific input. Add the following code to the `Test1` or `UnitTest1` class:
3535

3636
```csharp
3737
[TestMethod]
@@ -51,12 +51,16 @@ This walkthrough demonstrates how to develop a tested method in C# using Microso
5151

5252
4. Generate a type from the test code.
5353

54-
1. Place the cursor on `Rooter`, and then from the light bulb menu, choose **Generate type 'Rooter'** > **Generate new type**.
54+
1. Place the cursor on `Rooter`, and then open the light bulb menu.
5555

5656
::: moniker range=">=vs-2022"
57+
Choose **Generate new type**.
58+
5759
![Generate new type quick action](media/vs-2022/test-driven-development-generate-new-type.png)
5860
::: moniker-end
5961
::: moniker range="vs-2019"
62+
Choose **Generate type 'Rooter'** > **Generate new type**.
63+
6064
![Generate new type quick action](media/test-driven-development-generate-new-type.png)
6165
::: moniker-end
6266

@@ -69,7 +73,7 @@ This walkthrough demonstrates how to develop a tested method in C# using Microso
6973
![Generate Type dialog box in Visual Studio 2019](media/test-driven-development-generate-type-dialog.png)
7074
::: moniker-end
7175

72-
5. Generate a method from the test code. Place the cursor on `SquareRoot`, and then from the light bulb menu, choose **Generate method 'Rooter.SquareRoot'**.
76+
5. Generate a method from the test code. Place the cursor on `SquareRoot`, and then from the light bulb menu, choose **Generate method 'SquareRoot'** or **Generate method 'Rooter.SquareRoot'**.
7377

7478
6. Run the unit test.
7579

@@ -78,7 +82,7 @@ This walkthrough demonstrates how to develop a tested method in C# using Microso
7882
::: moniker range=">=vs-2022"
7983
To open Test Explorer from the **Test** menu, choose **Test Explorer**.
8084
::: moniker-end
81-
::: moniker range=">=vs-2022"
85+
::: moniker range="vs-2019"
8286
To open Test Explorer from the **Test** menu, choose **Windows** > **Test Explorer**.
8387
::: moniker-end
8488

@@ -193,11 +197,9 @@ To improve our confidence that the code works in all cases, add tests that try a
193197

194198
2. In **Test Explorer**, choose **Run All**.
195199

196-
The method under test loops and must be canceled manually.
197-
198-
3. Choose **Cancel** on the toolbar of **Test Explorer**.
200+
The new test fails.
199201

200-
The test stops executing.
202+
If the method under test loops, choose **Cancel** on the toolbar of **Test Explorer**. The test stops executing and fails.
201203

202204
4. Fix the `SquareRoot` code by adding the following `if` statement at the beginning of the method:
203205

0 commit comments

Comments
 (0)