Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/core/testing/unit-testing-mstest-running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The MSTest runner is open source and builds on the [MTP](./microsoft-testing-pla

## Enable MTP in an MSTest project

It's recommended to use [MSTest SDK](./unit-testing-mstest-sdk.md) as it greatly simplifies your project configuration and updating the project, and it ensures a proper alignment of the versions of the platform (MTP) and its extensions.
Use [MSTest SDK](./unit-testing-mstest-sdk.md) to greatly simplify your project configuration, version management, and alignment of MTP and its extensions.

When you use `MSTest SDK`, by default you're opted in to using MTP.
`MSTest.Sdk` replaces `Microsoft.NET.Sdk` as the project SDK, and MTP is enabled by default:

```xml
<Project Sdk="MSTest.Sdk/4.1.0">
Expand All @@ -39,7 +39,12 @@ When you use `MSTest SDK`, by default you're opted in to using MTP.
</Project>
```

Alternatively, you can enable MSTest runner by adding the `EnableMSTestRunner` property and setting `OutputType` to `Exe` in your project file. You also need to ensure that you're using `MSTest 3.2.0` or newer. We strongly recommend you update to the latest MSTest version available.
> [!NOTE]
> `MSTest.Sdk` works only when your project can use `Microsoft.NET.Sdk` as its base SDK. If your project requires a different SDK, don't replace the `<Project Sdk="...">` value with `MSTest.Sdk`.
>
> For example, ASP.NET Core integration test projects use `Microsoft.NET.Sdk.Web`. `MSTest.Sdk` derives from `Microsoft.NET.Sdk`, so it doesn't import the ASP.NET Core SDK targets that `Microsoft.NET.Sdk.Web` provides.
Comment thread
adegeo marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is stated too broadly. Most ASP.NET Core integration test projects use Microsoft.NET.Sdk (with WebApplicationFactory + the Microsoft.AspNetCore.Mvc.Testing package, which pulls in the framework reference automatically) — only some opt into Microsoft.NET.Sdk.Web. Since this example is the whole justification for the note, consider softening to something like "Some ASP.NET Core integration test projects use Microsoft.NET.Sdk.Web." to avoid implying it''s the norm.


If your project uses an SDK other than `Microsoft.NET.Sdk`, keep that SDK, and configure MSTest manually. Add the `EnableMSTestRunner` property and set `OutputType` to `Exe` in your project file. Then add the MSTest references that your project requires. Ensure that you're using MSTest 3.2.0 or newer, and update to the latest MSTest version available. The following example uses `Microsoft.NET.Sdk`, but the same properties work with other project SDKs (for example, `Microsoft.NET.Sdk.Web`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two thoughts on this paragraph:

  1. Add reassurance for the common case. For a test project it''s quite unlikely you''d need a base SDK other than ours — MSTest.Sdk (or plain Microsoft.NET.Sdk) covers almost every scenario. Worth a sentence so readers don''t over-think it, e.g. "For most test projects you won''t need a base SDK other than MSTest.Sdk; this only applies in rarer cases (such as ASP.NET Core integration tests) where the project genuinely requires a different SDK."

  2. Scope nuance: by scoping this to "If your project uses an SDK other than Microsoft.NET.Sdk", a reader on a plain Microsoft.NET.Sdk project who simply prefers manual configuration (no MSTest.Sdk) may think this section no longer applies to them. Consider "You can also configure MSTest manually — for example, when your project requires a different base SDK."

FYI I verified the combined-SDK path empirically: manually importing both Microsoft.NET.Sdk.Web and MSTest.Sdk does build and run tests, but emits MSB4011 duplicate-import warnings because both import Microsoft.NET.Sdk. So the manual-references approach you recommend here is the clean one — tracked upstream in microsoft/testfx#9562.


Consider the following example project file:

Expand Down
Loading