| name | mstest-testing-platform |
| description | Guide for using MSTest with Microsoft.Testing.Platform (the new test runner, not legacy VSTest) in .NET 10 projects |
| type | domain |
| enforcement | suggest |
| priority | high |
MSTest with Microsoft.Testing.Platform
This skill provides guidance for using Microsoft.Testing.Platform (the new test runner) with MSTest in this .NET 10 project. This is NOT the legacy VSTest runner.
Table of Contents
- Prerequisites
- Platform Overview
- Project Setup
- Running Tests
- Test Configuration
- Test Parallelization
- Debugging Tests
- CI/CD Integration
- Troubleshooting
- Quick Reference
Prerequisites
This project uses:
- .NET 10 SDK: 10.0.100-rc.2.25502.107 (configured in global.json)
- MSTest Package: 4.0.0-preview.25465.3 (configured in Directory.Packages.props)
- Microsoft.Testing.Platform: Included in MSTest 4.0.0+
The test runner is configured globally in global.json:
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
Platform Overview
Microsoft.Testing.Platform is the new test runner replacing legacy VSTest. Key differences:
- Command: Use
dotnet run --project (preferred) or dotnet test
- Performance: Faster, more efficient than VSTest
- Project Type: Requires
OutputType=Exe (not Library)
- Configuration: Requires
EnableMSTestRunner=true in .csproj
- MSTest Version: Requires 4.0.0+ (this project uses 4.0.0-preview.25465.3)
Project Setup
Required Project Configuration
All test projects in this repository require these properties:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" />
</ItemGroup>
</Project>
Key Properties:
EnableMSTestRunner: Enables Microsoft.Testing.Platform
OutputType=Exe: Makes the test project executable (required for the new runner)
- Package version is managed in
Directory.Packages.props (see dotnet-centralized-packages skill)
Current Test Projects
This repository has 4 test projects configured correctly:
tests/ClaudeStack.Web.Tests/ClaudeStack.Web.Tests.csproj
tests/ClaudeStack.API.Tests/ClaudeStack.API.Tests.csproj
tests/ClaudeStack.Web.Tests.Playwright/ClaudeStack.Web.Tests.Playwright.csproj
tests/ClaudeStack.API.Tests.Playwright/ClaudeStack.API.Tests.Playwright.csproj
All follow the same configuration pattern.
Running Tests
Primary Method: dotnet run
The preferred way to run tests with Microsoft.Testing.Platform:
dotnet run --project tests/ClaudeStack.Web.Tests/ClaudeStack.Web.Tests.csproj
dotnet run --project tests/ClaudeStack.Web.Tests
dotnet test
Test Filtering
Use the --filter option to run specific tests:
dotnet test --filter FullyQualifiedName~TestMethod1
dotnet test --filter FullyQualifiedName~ClaudeStack.Web.Tests.Test1
dotnet test --filter Name~Login
dotnet test --filter TestCategory=Integration
Running from Test Project Directory
cd tests/ClaudeStack.Web.Tests
dotnet run
dotnet test
Running All Tests
dotnet test
This runs all 4 test projects sequentially.
Test Configuration
MSTestSettings.cs
Each test project has a MSTestSettings.cs file for test execution configuration:
using Microsoft.VisualStudio.TestTools.UnitTesting;
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
This file controls test parallelization behavior (see next section).
Test Class Structure
Standard MSTest attributes: [TestClass], [TestMethod], [TestInitialize], [TestCleanup]
Important: ImplicitUsings is disabled. Always include: using Microsoft.VisualStudio.TestTools.UnitTesting;
Test Parallelization
Current Configuration
All test projects use method-level parallelization:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
This means test methods run in parallel within each test class.
Parallelization Scopes
Available options:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]
Controlling Parallelization
Disable parallelization for specific tests:
[TestClass]
[DoNotParallelize]
public class SequentialTests
{
[TestMethod]
public void MustRunSequentially()
{
}
}
Performance Considerations
- Method-level (current): Fastest, but tests must be thread-safe
- Class-level: Safer if tests share state within a class
- No parallelization: Slowest, but safest for tests with external dependencies
Debugging Tests
Visual Studio
- Set breakpoints in test code
- Right-click test → "Debug Test"
- Or use Test Explorer: Debug → Debug All Tests
Visual Studio Code
Use the .NET Core Test Explorer extension:
- Install extension
- Set breakpoints
- Click "Debug Test" in Test Explorer
Command Line Debugging
Not directly supported. Use IDE debugging instead.
Debug Output
Use TestContext to write debug output:
[TestClass]
public class MyTests
{
public TestContext TestContext { get; set; }
[TestMethod]
public void MyTest()
{
TestContext.WriteLine("Debug message");
}
}
Output appears in test results.
CI/CD Integration
Azure DevOps
Use the DotNetCoreCLI@2 task:
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*.Tests.csproj'
arguments: '--configuration Release'
GitHub Actions
- name: Run Tests
run: dotnet test --configuration Release
Test Results Publishing
dotnet test --logger "trx;LogFileName=test-results.trx"
In CI/CD, use --logger trx and publish with PublishTestResults@2 task (Azure DevOps) or upload artifacts (GitHub Actions).
Troubleshooting
Issue: Tests Don't Run
Symptoms: Test project builds but tests don't execute
Solution: Verify project configuration:
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
Issue: "dotnet test" Fails with Errors
Symptoms: dotnet test works but shows warnings or errors
Solution: Use dotnet run --project instead:
dotnet run --project tests/ClaudeStack.Web.Tests
Issue: Global.json Overwritten
Symptoms: After creating new test project, global.json is replaced
Cause: Using --test-runner flag with dotnet new mstest
Solution:
- NEVER use
--test-runner flag when creating test projects in this repository
- The test runner is already configured in global.json
- Correct command:
dotnet new mstest -o tests/NewProject
dotnet new mstest -o tests/NewProject --test-runner Microsoft.Testing.Platform
- After creating project, manually add to .csproj:
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
Issue: Tests Run Sequentially (Slow)
Symptoms: Tests take longer than expected
Solution: Verify MSTestSettings.cs has parallelization:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
Issue: Package Version Conflicts
Symptoms: Build errors about MSTest versions
Solution: Check Directory.Packages.props. Never add Version attribute to PackageReference in .csproj (see dotnet-centralized-packages skill).
Issue: Implicit Usings Errors
Symptoms: Missing namespace errors (e.g., "TestClass not found")
Solution: Add explicit using statements:
using Microsoft.VisualStudio.TestTools.UnitTesting;
ImplicitUsings is disabled in this project (Directory.Build.props).
Quick Reference
Commands
dotnet run --project tests/ClaudeStack.Web.Tests
dotnet test
dotnet test --filter FullyQualifiedName~TestMethod1
dotnet test --verbosity detailed
dotnet test --logger "trx;LogFileName=results.trx"
Required Project Properties
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
Required Package
<ItemGroup>
<PackageReference Include="MSTest" />
</ItemGroup>
Version managed in Directory.Packages.props.
MSTestSettings.cs Template
using Microsoft.VisualStudio.TestTools.UnitTesting;
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
Test Class Template
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace YourNamespace.Tests
{
[TestClass]
public class YourTests
{
[TestMethod]
public void YourTest()
{
var expected = true;
var actual = true;
Assert.AreEqual(expected, actual);
}
}
}
Creating New Test Project
dotnet new mstest -o tests/NewProject
dotnet sln add tests/NewProject/NewProject.csproj
Related Skills
- dotnet-centralized-packages: Managing package versions in Directory.Packages.props
- playwright-dotnet: E2E testing with Playwright and MSTest integration
- dotnet-cli-essentials: General .NET CLI commands and patterns
Version Information
- MSTest: 4.0.0-preview.25465.3
- Microsoft.Testing.Platform: Included in MSTest 4.0.0+
- .NET SDK: 10.0.100-rc.2.25502.107
This skill is accurate as of .NET 10 RC 2. Some details may change in the RTM release.
Additional Resources