Skip to content

Commit f58c9b0

Browse files
authored
Merge pull request #6210 from Mikejo5000/mikejo-br16
NUnit test update
2 parents f2e1c07 + ac38cd0 commit f58c9b0

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

docs/test/getting-started-with-unit-testing.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Get started with unit testing
3-
ms.date: 02/13/2020
3+
ms.date: 03/04/2020
44
ms.topic: conceptual
55
helpviewer_keywords:
66
- unit testing, create unit test plans
@@ -16,7 +16,7 @@ Use Visual Studio to define and run unit tests to maintain code health, ensure c
1616

1717
## Create unit tests
1818

19-
This section describes at a high level how to create a unit test project.
19+
This section describes how to create a unit test project.
2020

2121
1. Open the project that you want to test in Visual Studio.
2222

@@ -66,7 +66,7 @@ This section describes at a high level how to create a unit test project.
6666

6767
1. Add code to the unit test method.
6868

69-
For example, for an MSTest or NUnit test project, you might use the following code.
69+
For example, for an MSTest project, you might use the following code.
7070

7171
```csharp
7272
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -95,8 +95,42 @@ This section describes at a high level how to create a unit test project.
9595
}
9696
```
9797

98+
Or, for an NUnit project, you might use the following code.
99+
100+
```csharp
101+
using using NUnit.Framework;
102+
using System.IO;
103+
using System;
104+
105+
namespace HelloWorldTests
106+
{
107+
[TestClass]
108+
public class Tests
109+
{
110+
private const string Expected = "Hello World!";
111+
112+
[SetUp]
113+
public void Setup()
114+
{
115+
}
116+
[Test]
117+
public void TestMethod1()
118+
{
119+
using (var sw = new StringWriter())
120+
{
121+
Console.SetOut(sw);
122+
HelloWorldCore.Program.Main();
123+
124+
var result = sw.ToString().Trim();
125+
Assert.AreEqual(Expected, result);
126+
}
127+
}
128+
}
129+
}
130+
```
131+
98132
> [!TIP]
99-
> For a more detailed walkthrough of creating unit tests, see [Create and run unit tests for managed code](walkthrough-creating-and-running-unit-tests-for-managed-code.md).
133+
> For more details about creating unit tests, see [Create and run unit tests for managed code](walkthrough-creating-and-running-unit-tests-for-managed-code.md).
100134
101135
## Run unit tests
102136

0 commit comments

Comments
 (0)