Skip to main content

MSTest by Microsoft

NuGet / site data​

Nuget GitHub last commit GitHub Repo stars

Details​

Info​

info

Name: MSTest

Microsoft.Testing is a set of platform, framework and protocol intended to make it possible to run any test on any target or device.

This package provides the C# source generators for MSTest test framework.

Author: Microsoft

NuGet: https://www.nuget.org/packages/MSTest.SourceGeneration/

You can find more details at https://github.com/microsoft/testfx

Source: https://github.com/microsoft/testfx

Original Readme​

note

Microsoft Test Framework

GitHub release GitHub repo size GitHub issues-opened GitHub issues-closed GitHub pulls-opened GitHub pulls-merged GitHub contributors Build Status

MSTest, Microsoft Testing Framework, is a unit testing framework for .NET applications. It allows you to write tests, use Test Explorer, create test suites, and apply the red, green, refactor pattern to write code.

This is a fully supported, open source and cross-platform test framework with which to write tests targeting .NET Framework, .NET Core, .NET, UWP and WinUI on Windows, Linux, and Mac.

How can I contribute?​

We welcome any kind of contribution!

  • Contributing provides guidance on how to best contribute
  • Dev Guide explains how to build and test
  • Documentation contains information about history, context and supported or unsupported features. It also gather the various official documentation pages on learn.microsoft.com about MSTest.

How to consume MSTest?​

MSTest is shipped as NuGet packages that can be added to your projects. The following table lists all available packages.

NameDescriptionStable versionPreview versionDogfood version
MSTestThis package is a meta package that simplifies referencing all recommended MSTest packages.##Azure Artifacts
MSTest.TestFrameworkThis package includes the libraries for writing tests with MSTest. To ensure discovery and execution of your tests, install the `MSTest.TestAdapter`` package.##Azure Artifacts
MSTest.TestAdapterThis package includes the adapter logic to discover and run tests. For access to the testing framework, install the MSTest.TestFramework package.##Azure Artifacts
MSTest.AnalyzersThis package includes code analyzers and code fixes for MSTest.##Azure Artifacts

License​

MSTest is licensed under the MIT license.

The LICENSE and ThirdPartyNotices in any downloaded archives are authoritative.

About​

note

AOP for MSTest

How to use​

Example (source csproj, source files)​

This is the CSharp Project that references MSTest

<!-- file: UnitTestProject1.csproj -->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<OutputType>exe</OutputType>
<PublishAot>true</PublishAot>
</PropertyGroup>

<ItemGroup>
<!--
Experimental MSTest Engine & source generator,
close sourced, licensed the same as our extensions
with Microsoft Testing Platform Tools license.
-->
<PackageReference Include="MSTest.Engine" Version="1.0.0-alpha.24163.4" />
<PackageReference Include="MSTest.SourceGeneration" Version="1.0.0-alpha.24163.4" />

<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="17.10.4" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.4" />

<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.2" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="1.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="MSTest.Analyzers" Version="3.2.2" />

</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MyImportantClass\MyImportantClass.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

</Project>

Generated Files​

Those are taken from $(BaseIntermediateOutputPath)\GX

//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by Microsoft Testing Framework Generator.
// </auto-generated>
//------------------------------------------------------------------------------

namespace DemoTest
{
using Threading = global::System.Threading;
using ColGen = global::System.Collections.Generic;
using CA = global::System.Diagnostics.CodeAnalysis;
using Sys = global::System;
using Msg = global::Microsoft.Testing.Platform.Extensions.Messages;
using MSTF = global::Microsoft.Testing.Framework;

[CA::ExcludeFromCodeCoverage]
public static class DemoTest_UnitTest1
{
public static readonly MSTF::TestNode TestNode = new MSTF::TestNode
{
StableUid = "DemoTest.DemoTest.UnitTest1",
DisplayName = "UnitTest1",
Properties = new Msg::IProperty[1]
{
new Msg::TestFileLocationProperty(@"D:\eu\GitHub\RSCG_Examples\v2\rscg_examples\MSTest\src\DemoTest\UnitTest1.cs", new(new(6, -1), new(22, -1))),
},
Tests = new MSTF::TestNode[]
{
new MSTF::InternalUnsafeActionTestNode
{
StableUid = "DemoTest.DemoTest.UnitTest1.TestMethod1()",
DisplayName = "TestMethod1",
Properties = new Msg::IProperty[2]
{
new Msg::TestMethodIdentifierProperty(
"DemoTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"DemoTest",
"UnitTest1",
"TestMethod1",
Sys::Array.Empty<string>(),
"System.Void"),
new Msg::TestFileLocationProperty(@"D:\eu\GitHub\RSCG_Examples\v2\rscg_examples\MSTest\src\DemoTest\UnitTest1.cs", new(new(9, -1), new(13, -1))),
},
Body = static testExecutionContext =>
{
var instance = new UnitTest1();
try
{
instance.TestMethod1();
}
catch (global::System.Exception ex)
{
testExecutionContext.ReportException(ex, null);
}
},
},
new MSTF::InternalUnsafeActionParameterizedTestNode<MSTF::InternalUnsafeTestArgumentsEntry<(int left, int right)>>
{
StableUid = "DemoTest.DemoTest.UnitTest1.TestMethod2(int, int)",
DisplayName = "TestMethod2",
Properties = new Msg::IProperty[2]
{
new Msg::TestMethodIdentifierProperty(
"DemoTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"DemoTest",
"UnitTest1",
"TestMethod2",
new string[2]
{
"System.Int32",
"System.Int32",
},
"System.Void"),
new Msg::TestFileLocationProperty(@"D:\eu\GitHub\RSCG_Examples\v2\rscg_examples\MSTest\src\DemoTest\UnitTest1.cs", new(new(15, -1), new(21, -1))),
},
GetArguments = static () => new MSTF::InternalUnsafeTestArgumentsEntry<(int left, int right)>[]
{
new MSTF::InternalUnsafeTestArgumentsEntry<(int left, int right)>((1, 2), "left: 1, right: 2"),
new MSTF::InternalUnsafeTestArgumentsEntry<(int left, int right)>((100, -97), "left: 100, right: -97"),
},
Body = static (testExecutionContext, data) =>
{
var instance = new UnitTest1();
try
{
instance.TestMethod2(data.Arguments.left, data.Arguments.right);
}
catch (global::System.Exception ex)
{
testExecutionContext.ReportException(ex, null);
}
},
},
},
};
}
}

Useful​

Download Example (.NET C#)​

Share MSTest​

https://ignatandrei.github.io/RSCG_Examples/v2/docs/MSTest

aaa

Category "Tests" has the following generators:​

1 Forged Nuget GitHub Repo stars 2026-09-12

2 Imposter Nuget GitHub Repo stars 2025-12-13

3 KnockOff Nuget GitHub Repo stars 2026-02-13

4 mocklis Nuget GitHub Repo stars 2024-01-03

5 MockMe Nuget GitHub Repo stars 2025-02-10

6 MSTest Nuget GitHub Repo stars 2024-04-04

7 Ridge Nuget GitHub Repo stars 2023-08-20

8 Rocks Nuget GitHub Repo stars 2023-04-16

9 SatorImaging.TDoubles Nuget GitHub Repo stars 2026-08-27

10 TinyBDD.MSTest Nuget GitHub Repo stars 2026-07-03

11 TUnit Nuget GitHub Repo stars 2025-11-08

See category​

Tests