Skip to content

Commit 1b8fcea

Browse files
ncarandiniBillWagner
authored andcommitted
Add MSTest tutorial (dotnet#915) (dotnet#921)
* Create using-mstest article * Fix using directives (from xunit to MSTest) * Remove unecessary step 9 * Small change on introduction * Add MSTest to the writing the test project title * Change is maybe to could be * add author GitHub ID * Change MSUnit to MSTest * Add manager info (wpickett) * Add ms.assetid (generated GUID) * Fix "using on windows" link * Fix "Important" markup code * Remove the * versions on step 5 * Move using-ms-test-on-windows to docs\core\testing * Update toc.md entry * Fix link due to move in another folder * Add links to document
1 parent 3588133 commit 1b8fcea

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

docs/core/testing/unit-testing-with-dotnet-test.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,6 @@ You've built a small library and a set of unit tests for that library.
250250
You've structured this solution so that adding new packages and tests
251251
will be seamless, and you can concentrate on the problem at hand. The
252252
tools will run automatically.
253+
254+
> [!TIP]
255+
> On Windows platform you can you can use MSTest. You can find out more in the [Using MSTest on Windows document](./using-mstest-on-windows.md).
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Use MSTest with .NET Core on Windows
3+
description: How to use MSTest with .NET Core on Windows, using Visual Studio 2015
4+
keywords: MSTest, .NET, .NET Core
5+
author: ncarandini
6+
manager: wpickett
7+
ms.date: 08/18/2016
8+
ms.topic: article
9+
ms.prod: .net-core
10+
ms.technology: .net-core-technologies
11+
ms.devlang: dotnet
12+
ms.assetid: ed447641-3e85-4e50-b7ed-004630048a3e
13+
---
14+
15+
# Unit testing with MSTest and .NET Core on Windows, using Visual Studio 2015
16+
17+
by [Nicolò Caradini](https://github.com/ncarandini)
18+
19+
While xUnit could be a better choice when targeting multiple platforms, with .NET Core on Windows is also possible to use MSTest.
20+
21+
## Prerequisites
22+
23+
Follow the instructions on [Getting started with .NET Core on Windows](../tutorials/using-on-windows.md) to create the library project.
24+
25+
### Writing the test project using MSTest
26+
27+
1. In Solution Explorer, open the context menu for the **Solution** node and choose **Add**, **New Solution Folder**. Name the folder "test".
28+
This is only a solution folder, not a physical folder.
29+
30+
2. Open the context menu for the **test** folder and choose **Add**. **New Project**. In the **New Project** dialog, choose **Console Application (.NET Core)**. Name it "TestLibrary" and explicitly put it under the `Golden\test` path.
31+
32+
> [!IMPORTANT]
33+
> The project needs to be a console application, not a class library.
34+
35+
3. In the **TestLibrary** project, open the context menu for the **References** node and choose **Add Reference**.
36+
37+
4. In the **Reference Manager** dialog, check **Library** under the **Projects**, **Solution** node, and then click **OK**.
38+
39+
5. In the **TestLibrary** project, open the `project.json` file, and replace `"Library": "1.0.0-*"` with `"Library": {"target": "project"}`.
40+
41+
This is to avoid the resolution of the `Library` project to a NuGet package with the same name. Explicitly setting the target to "project" ensures that the tooling will first search for a project with that name, and not a package.
42+
43+
6. Open the context menu for the **References** node and choose **Manage NuGet Packages**.
44+
45+
7. Choose "nuget.org" as the **Package source**, and choose the **Browse** tab. Check the **Include prerelease** checkbox, and then browse for **MSTest.TestFramework** version 1.0.1-preview or newer, and then click **Install**.
46+
47+
8. Browse for **dotnet-test-mstest** version 1.1.1-preview or newer, and then click **Install**.
48+
49+
9. Edit `project.json` to add `"testRunner": "mstest",` after the `"version"` section.
50+
51+
10. Add a `LibraryTests.cs` class file to the **TestLibrary** project, add the `using` directives `Microsoft.VisualStudio.TestTools.UnitTesting;` and `using Library;` to the top of the file, and add the following code to the class:
52+
```csharp
53+
[TestClass]
54+
public class LibraryTests
55+
{
56+
[TestMethod]
57+
public void ThingGetsObjectValFromNumber()
58+
{
59+
Assert.AreEqual(42, new Thing().Get(42));
60+
}
61+
}
62+
```
63+
* Optionally, delete the `Program.cs` file from the **TestLibrary** project, and remove `"buildOptions": {"emitEntryPoint": true},` from `project.json`.
64+
65+
You should now be able to build the solution.
66+
67+
11. On the **Test** menu, choose **Windows**, **Test Explorer**, and in Test Explorer choose **Run All**.
68+
69+
The test should pass.

docs/core/tutorials/using-on-windows.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ Starting from the solution obtained with the previous script, execute the follow
165165
14. Press F5 to run the app.
166166

167167
The application should build and hit the breakpoint. The application output should be "The answer is 42.".
168+
169+
> [!TIP]
170+
> On Windows platform you can you can use MSTest. You can find out more in the [Using MSTest on Windows document](../testing/using-mstest-on-windows.md).
168171

169172
Moving a library from netstandard 1.4 to 1.3
170173
--------------------------------------------

docs/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
### [Creating a NuGet Package with Cross Platform Tools](core/deploying/creating-nuget-packages.md)
258258
## [Unit Testing](core/testing/index.md)
259259
### [Unit Testing with dotnet test](core/testing/unit-testing-with-dotnet-test.md)
260+
### [Unit testing with MSTest on Windows](core/testing/using-mstest-on-windows.md)
260261
## [Releases](core/versions/index.md)
261262
### [Servicing](core/versions/servicing.md)
262263
## [Runtime IDentifier catalog](core/rid-catalog.md)

0 commit comments

Comments
 (0)