{"id":51369,"date":"2024-04-11T10:05:00","date_gmt":"2024-04-11T17:05:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=51369"},"modified":"2024-04-12T09:02:30","modified_gmt":"2024-04-12T16:02:30","slug":"introducing-mstest-sdk","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-mstest-sdk\/","title":{"rendered":"Introducing MSTest SDK &#8211; Improved Configuration &amp; Flexibility"},"content":{"rendered":"<p>We are excited to announce the new MSTest SDK built on top of the MSBuild Project SDK system. It is designed to give you a better experience for testing with MSTest by making project configuration easier through sensible defaults and flexible options.<\/p>\n<p>This new experience was built on top of the recently introduced MSTest runner (<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-ms-test-runner\/\">check out the announcement post<\/a>) to further simplify your experience. This new runner, a lightweight, reliable, and performant way to run MSTest tests, is shipped as dependency of <code>MSTest.TestAdapter<\/code> NuGet package. The runner and its extensions consist of multiple NuGet packages to provide an extensible, flexible, and configurable test running experience. However, being customizable can result in many questions: What are the recommended extensions? What are the correct defaults? How do I align the versions? This is where the MSTest SDK comes in.<\/p>\n<h2>Getting started with MSTest SDK<\/h2>\n<p>Getting started using the new MSTest SDK is easy. Just create a MSTest project (or update an existing MSTest project) and replace the content of the <code>.csproj<\/code> file with the following:<\/p>\n<pre><code class=\"language-xml\">&lt;Project Sdk=\"MSTest.Sdk\/3.3.1\"&gt;\r\n\r\n  &lt;PropertyGroup&gt; \r\n      &lt;TargetFramework&gt;net8.0&lt;\/TargetFramework&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n\r\n  &lt;!-- Additional properties and items for your tests. --&gt;\r\n&lt;\/Project&gt; <\/code><\/pre>\n<p>Note that you can use any target framework supported by MSTest (i.e. <code>net462<\/code> and above).<\/p>\n<h2>Advantages of MSTest SDK<\/h2>\n<p>This new SDK offers many advantages for you and your test projects, such as: <\/p>\n<ul>\n<li>Better defaults<\/li>\n<li>Simplified usage<\/li>\n<li>Extensibility of the MSTest runner<\/li>\n<li>Easier opt-in for new features (e.g. native AOT tests).<\/li>\n<\/ul>\n<h3>Better defaults<\/h3>\n<p>When using the MSTest SDK, you are aligning with the patterns that are provided by the main types of applications such as ASP.NET Core, Razor, Windows Desktop. It will use the default suggestions that the MSTest team makes for your test projects.<\/p>\n<p>For example, we introduced some MSTest static code analyzers with v3.2 but these analyzers are defined in a new package that is not available by default so you would have to manually add this package to your test projects. Instead, by using MSTest SDK, you would simply bump the version and get all the new defaults.<\/p>\n<p>We want to call out that we are following semantic versioning (see this <a href=\"https:\/\/learn.microsoft.com\/dotnet\/csharp\/versioning#semantic-versioning\">article about semantic versioning<\/a>) principles closely when choosing the defaults and updating them between versions, so you have the guarantee of understandable and easy updates.<\/p>\n<h3>Easier usage of MSTest Runner extensions<\/h3>\n<p>In addition to <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/introducing-ms-test-runner\/\">MSTest runner<\/a>, we are also shipping a set of extensions that you can install as NuGet packages to enhance your testing experience. To help you select the right defaults, the right extensions and to make sure you have easy update and alignments between the extensions, we are introducing a new concept of &#8220;profiles&#8221;. We are currently providing the following 3 profiles: <code>Default<\/code>, <code>AllMicrosoft<\/code> and <code>None<\/code>, that you can configure and further customize. With <code>Default<\/code> profile being our recommendation.<\/p>\n<p>The default profile contains:<\/p>\n<ul>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Testing.Extensions.CodeCoverage\">Microsoft Code Coverage<\/a><\/li>\n<li><a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.Testing.Extensions.TrxReport\">TRX report support<\/a><\/li>\n<\/ul>\n<p>Starting from any profile, you can then manually opt-in or opt-out any additional extension adding some additional properties to your project that would follow the pattern <code>Enable[NugetPackageNameWithoutDots]<\/code>. For example, to add crash dump support to the default profile you can simply add the following MSBuild property <code>EnableMicrosoftTestingExtensionsCrashDump<\/code> set to <code>true<\/code>.<\/p>\n<pre><code class=\"language-xml\">&lt;Project Sdk=\"MSTest.Sdk\/3.3.1\"&gt;\r\n\r\n  &lt;PropertyGroup&gt;\r\n      &lt;TargetFramework&gt;net8.0&lt;\/TargetFramework&gt;\r\n      &lt;!-- Enable Microsoft.Testing.Extensions.CrashDump package on top of the default profile --&gt;\r\n      &lt;EnableMicrosoftTestingExtensionsCrashDump&gt;true&lt;\/EnableMicrosoftTestingExtensionsCrashDump&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n\r\n  &lt;!-- Additional properties and items for your tests. --&gt;\r\n&lt;\/Project&gt; <\/code><\/pre>\n<p>You can refer to our <a href=\"https:\/\/learn.microsoft.com\/dotnet\/core\/testing\/unit-testing-mstest-sdk#available-extensions\">MSTest SDK documentation<\/a> to get more information about these profiles and their defaults.<\/p>\n<h3>Testing Native AOT<\/h3>\n<p>MSTest is the first .NET Test Framework and runner to support running tests in Native AOT mode. When using MSTest SDK, we will automatically detect if you are publishing to AOT and transparently swap all required test packages and configurations to match this specialized mode.<\/p>\n<p>For more information about testing with Native AOT, please refer to this blog post: <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/testing-your-native-aot-dotnet-apps\/\">Testing with Native AOT blog post<\/a>.<\/p>\n<p>Example of project setup <em>without<\/em> MSTest SDK:<\/p>\n<pre><code class=\"language-xml\">&lt;Project Sdk=\"Microsoft.NET.Sdk\"&gt;\r\n\r\n  &lt;PropertyGroup&gt;\r\n    &lt;TargetFramework&gt;net8.0&lt;\/TargetFramework&gt;\r\n    &lt;ImplicitUsings&gt;enable&lt;\/ImplicitUsings&gt;\r\n    &lt;Nullable&gt;enable&lt;\/Nullable&gt;\r\n\r\n    &lt;OutputType&gt;exe&lt;\/OutputType&gt;\r\n    &lt;PublishAot&gt;true&lt;\/PublishAot&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n\r\n  &lt;ItemGroup&gt;\r\n    &lt;!-- \r\n      Experimental MSTest Engine &amp; source generator, \r\n      close sourced, licensed the same as our extensions \r\n      with Microsoft Testing Platform Tools license.\r\n    --&gt;\r\n    &lt;PackageReference Include=\"MSTest.Engine\" Version=\"1.0.0-alpha.24163.4\" \/&gt;\r\n    &lt;PackageReference Include=\"MSTest.SourceGeneration\" Version=\"1.0.0-alpha.24163.4\" \/&gt;\r\n\r\n    &lt;PackageReference Include=\"Microsoft.CodeCoverage.MSBuild\" Version=\"17.10.4\" \/&gt;\r\n    &lt;PackageReference Include=\"Microsoft.Testing.Extensions.CodeCoverage\" Version=\"17.10.4\" \/&gt;\r\n\r\n    &lt;PackageReference Include=\"Microsoft.Testing.Extensions.TrxReport\" Version=\"1.0.2\" \/&gt;\r\n    &lt;PackageReference Include=\"Microsoft.Testing.Platform.MSBuild\" Version=\"1.0.2\" \/&gt;\r\n    &lt;PackageReference Include=\"MSTest.TestFramework\" Version=\"3.2.2\" \/&gt;\r\n    &lt;PackageReference Include=\"MSTest.Analyzers\" Version=\"3.2.2\" \/&gt;\r\n  &lt;\/ItemGroup&gt;\r\n\r\n  &lt;ItemGroup&gt;\r\n    &lt;ProjectReference Include=\"..\\ClassLibrary1\\ClassLibrary1.csproj\" \/&gt;\r\n  &lt;\/ItemGroup&gt;\r\n\r\n  &lt;ItemGroup&gt;\r\n    &lt;Using Include=\"Microsoft.VisualStudio.TestTools.UnitTesting\" \/&gt;\r\n  &lt;\/ItemGroup&gt;\r\n\r\n&lt;\/Project&gt;<\/code><\/pre>\n<p>The same project setup <em>with<\/em> MSTest SDK:<\/p>\n<pre><code class=\"language-xml\">&lt;Project Sdk=\"MSTest.Sdk\/3.3.1\"&gt;\r\n\r\n  &lt;PropertyGroup&gt;\r\n    &lt;TargetFramework&gt;net8.0&lt;\/TargetFramework&gt;\r\n    &lt;ImplicitUsings&gt;enable&lt;\/ImplicitUsings&gt;\r\n    &lt;Nullable&gt;enable&lt;\/Nullable&gt;\r\n    &lt;PublishAot&gt;true&lt;\/PublishAot&gt;\r\n  &lt;\/PropertyGroup&gt;\r\n\r\n  &lt;ItemGroup&gt;\r\n    &lt;ProjectReference Include=\"..\\ClassLibrary1\\ClassLibrary1.csproj\" \/&gt;\r\n  &lt;\/ItemGroup&gt;\r\n\r\n  &lt;ItemGroup&gt;\r\n    &lt;Using Include=\"Microsoft.VisualStudio.TestTools.UnitTesting\" \/&gt;\r\n  &lt;\/ItemGroup&gt;\r\n\r\n&lt;\/Project&gt;<\/code><\/pre>\n<h2>What&#8217;s next?<\/h2>\n<p>The MSTest SDK style, while still in development, stands as the cornerstone of our forthcoming evolutions and features. We strongly encourage all MSTest users to transition to this SDK style that will become our standard for the MSTest project template with .NET 9.<\/p>\n<p>We are also planning to add more scenarios in upcoming releases such as Playwright and WinUI.<\/p>\n<p>We welcome any feedback on how to improve and refine it further, ensuring it aligns with the diverse needs and expectations of our users. The best way to share feedback is to creat an issue in our <a href=\"https:\/\/github.com\/microsoft\/testfx\">microsoft\/testfx<\/a> repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The new MSTest SDK is here and provides an easier way to configure your MSTest projects. Learn all about this release, how to get started, and its great improvements when using MSTest.<\/p>\n","protected":false},"author":138175,"featured_media":51370,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,756],"tags":[7784,136],"class_list":["post-51369","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-csharp","tag-mstest","tag-testing"],"acf":[],"blog_post_summary":"<p>The new MSTest SDK is here and provides an easier way to configure your MSTest projects. Learn all about this release, how to get started, and its great improvements when using MSTest.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/51369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/138175"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=51369"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/51369\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/51370"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=51369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=51369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=51369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}