-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MSTest: getting started, writing tests and running tests (#41826)
- Loading branch information
1 parent
91095ba
commit 560c4b3
Showing
6 changed files
with
556 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: Get started with MSTest | ||
description: Learn about how to install MSTest. | ||
author: Evangelink | ||
ms.author: amauryleve | ||
ms.date: 07/24/2024 | ||
--- | ||
|
||
# Get started with MSTest | ||
|
||
MSTest functionality is split into multiple NuGet packages: | ||
|
||
- [MSTest.TestFramework](https://www.nuget.org/packages/MSTest.TestFramework): Contains the attributes and classes that are used to define MSTest tests. | ||
- [MSTest.TestAdapter](https://www.nuget.org/packages/MSTest.TestAdapter): Contains the test adapter that discovers and runs MSTest tests. | ||
- [MSTest.Analyzers](https://www.nuget.org/packages/MSTest.Analyzers): Contains the analyzers that helps you write high-quality tests. | ||
|
||
We recommend that you don't install these packages directly into your test projects. Instead, you should use either: | ||
|
||
- [MSTest.Sdk](https://www.nuget.org/packages/MSTest.Sdk): A [MSBuild project SDK](/visualstudio/msbuild/how-to-use-project-sdk) that includes all the recommended packages and greatly simplifies all the boilerplate configuration. Although this is shipped as a NuGet package, it's not intended to be installed as a regular package dependency, instead you should modify the `Sdk` part of your project (e.g. `<Project Sdk="MSTest.Sdk">` or `<Project Sdk="MSTest.Sdk/X.Y.Z">` where `X.Y.Z` is MSTest version). For more information, please refer to [MSTest SDK overview](./unit-testing-mstest-sdk.md). | ||
|
||
- the [MSTest](https://www.nuget.org/packages/MSTest) NuGet package, which includes all recommended packages: `MSTest.TestFramework`, `MSTest.TestAdapter`, `MSTest.Analyzer` and `Microsoft.NET.Test.Sdk`. | ||
|
||
If you are creating a test infrastructure project that is intended to be used as a helper by multiple test projects, you should install the `MSTest.TestFramework` and `MSTest.Analyzers` packages directly into that project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Run tests with MSTest | ||
description: Learn about how to run MSTest tests. | ||
author: Evangelink | ||
ms.author: amauryleve | ||
ms.date: 07/24/2024 | ||
--- | ||
|
||
# Run tests with MSTest | ||
|
||
There are several ways to run MSTest tests depending on your needs. You can run tests from an IDE (for example, Visual Studio, Visual Studio Code, or JetBrains Rider), or from the command line, or from a CI service (such as GitHub Actions or Azure DevOps). | ||
|
||
Historically, MSTest relied on [VSTest](https://github.com/microsoft/vstest) for running tests in all contexts but starting with version 3.2.0, MSTest has its own [test runner](./unit-testing-mstest-runner-intro.md). This new runner is more lightweight and faster than VSTest, and it's the recommended way to run MSTest tests. |
23 changes: 23 additions & 0 deletions
23
docs/core/testing/unit-testing-mstest-writing-tests-assertions.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: MSTest assertions | ||
description: Learn about MSTest assertions. | ||
author: Evangelink | ||
ms.author: amauryleve | ||
ms.date: 07/24/2024 | ||
--- | ||
|
||
# MSTest assertions | ||
|
||
Use the `Assert` classes of the <xref:Microsoft.VisualStudio.TestTools.UnitTesting> namespace to verify specific functionality. A test method exercises the code of a method in your application's code, but it reports the correctness of the code's behavior only if you include `Assert` statements. | ||
|
||
## The `Assert` class | ||
|
||
In your test method, you can call any methods of the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert?displayProperty=fullName> class, such as <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual%2A?displayProperty=nameWithType>. The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert> class has many methods to choose from, and many of the methods have several overloads. | ||
|
||
## The `StringAssert` class | ||
|
||
Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert> class to compare and examine strings. This class contains a variety of useful methods, such as <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.Contains%2A?displayProperty=nameWithType>, <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.Matches%2A?displayProperty=nameWithType>, and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.StartsWith%2A?displayProperty=nameWithType>. | ||
|
||
## The `CollectionAssert` class | ||
|
||
Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert> class to compare collections of objects, or to verify the state of a collection. |
Oops, something went wrong.