Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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:
- Data-driven testing: Run tests with multiple inputs using
DataRow,DynamicData, and external data sources. - Test lifecycle management: Setup and cleanup at assembly, class, and test levels.
- Parallel execution: Run tests concurrently to reduce execution time.
- Test organization: Categorize, prioritize, and filter tests with metadata attributes.
- Code analyzers: Detect common issues and enforce best practices at compile time.
- Assertions: Comprehensive assertion methods for validating results.
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 |
Requires settings <UseUwp>true</UseUwp>; see UWP sample |
| WinUI 3 | .NET 8+ | UI thread | UITestMethod |
Requires Windows App SDK; see WinUI sample |
| Native AOT | .NET 8+ | Full parallelization | Most attributes | Limited feature set; see Native AOT sample |
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);
}
}
For 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);
}
}
For WinUI setup, see the BlankWinUINet9App sample and MSTestRunnerWinUI 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.
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 Microsoft.Testing.Platform (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
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.