Redaguoti

MSTest overview

MSTest, Microsoft Testing Framework, is a fully supported, open-source, and cross-platform test framework for .NET applications. It allows you to write and execute tests, and provides test suites with integration to Visual Studio and Visual Studio Code Test Explorers, the .NET CLI, and many CI pipelines.

MSTest is hosted on GitHub and works with all supported .NET targets.

Key features

MSTest provides comprehensive testing capabilities:

Supported platforms

MSTest supports a wide range of .NET platforms and target frameworks. The following table summarizes platform support and special considerations:

Platform Target frameworks Threading support Special attributes Notes
.NET .NET 8+ Full parallelization All attributes Recommended for new projects
.NET Framework 4.6.2+ Full parallelization All attributes Full feature support
UWP UAP 10, .NET 9+ with UAP UI thread UITestMethod Use VSTest. Modern .NET UWP requires <UseUwp>true</UseUwp>; see UWP sample
WinUI 3 .NET 8+ UI thread UITestMethod Requires Windows App SDK; see Test WinUI 3 apps with MSTest and MTP
Native AOT .NET 8+ Full parallelization Most attributes Limited feature set; see Native AOT sample
Browser WebAssembly .NET 10+ custom host Single-threaded Limited Custom Microsoft.Testing.Platform host support starts with MSTest 4.4

Platform-specific considerations

UWP testing

UWP tests run in the UWP app container and require the UI thread for many operations:

[TestClass]
public class UwpTests
{
    [UITestMethod]
    public void TestUwpControl()
    {
        // Test runs on UI thread
        var button = new Button();
        Assert.IsNotNull(button);
    }
}

Use VSTest for classic UWP and modern .NET UWP because both run in an AppContainer. For a modern .NET UWP setup, see the BlankUwpNet9App sample.

WinUI 3 testing

WinUI 3 tests also require UI thread access for testing visual components:

[TestClass]
public class WinUITests
{
    [UITestMethod]
    public void TestWinUIControl()
    {
        // Test runs on UI thread
        var window = new MainWindow();
        Assert.IsNotNull(window);
    }
}

To configure unpackaged or packaged full-trust WinUI 3 tests, see Test WinUI 3 apps with MSTest and MTP.

Starting with MSTest 4.4, Microsoft.Testing.Platform also supports unpackaged WinUI test applications. VSTest doesn't support this scenario. For setup details, see the unpackaged WinUI sample.

Native AOT

Native AOT compilation is supported with some limitations due to reduced reflection capabilities. Use source generators where possible and test your AOT scenarios with the NativeAotRunner sample.

Browser WebAssembly

Starting with MSTest 4.4, a custom .NET 10 browser WebAssembly host can call AddMSTest to run tests from a referenced MSTest assembly. In the host project, set EnableMSTestRunner to true and GenerateTestingPlatformEntryPoint to false so the custom host owns the application entry point. Keep the MSTest and Microsoft.Testing.Platform package versions aligned.

On a single-threaded WebAssembly runtime, MSTest can't interrupt timed-out tests, and debugger launch options aren't supported. For a complete host, see the BrowserPlayground sample.

STA threading support

For Windows COM interop scenarios, MSTest provides STATestClass and STATestMethod attributes to run tests in a single-threaded apartment. For details on STA threading, including async continuation support with UseSTASynchronizationContext, see Threading attributes.

Test runners

MSTest supports two test execution platforms:

  • Microsoft.Testing.Platform (MTP): The modern, recommended test platform with improved performance and extensibility.
  • VSTest: The original and default test platform for .NET.

For new projects, we recommend using MTP with MSTest.Sdk.

MSTest support policy

Since v3.0.0, MSTest strictly follows semantic versioning.

The MSTest team only supports the latest released version and strongly encourages users to always update to the latest version to benefit from improvements and security patches. Preview releases aren't supported by Microsoft but are offered for public testing ahead of final release.

Version history

MSTest has undergone significant evolution across major versions:

  • MSTest v1: The original Visual Studio testing framework
  • MSTest v2: First open-source release with cross-platform support
  • MSTest v3: Modern rewrite with improved architecture and features
  • MSTest v4: Current version with enhanced features

Note

MSTest 4.4 is under development as of August 2026. Features marked as introduced in MSTest 4.4 require a preview build until version 4.4.0 is released.

For details on all releases, see the MSTest changelog.

If you're upgrading from an older version, see the migration guides:

Breaking changes

The MSTest team carefully reviews and minimizes breaking changes. When breaking changes are necessary, the team uses GitHub Announcements and breaking change labels on issues to inform the community early, giving users time to provide feedback and raise concerns before changes are released.

Next steps