Guide for using MSTest with Microsoft.Testing.Platform (the new test runner, not legacy VSTest) in .NET 10 projects
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.
This project uses:
The test runner is configured globally in global.json:
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
Microsoft.Testing.Platform is the new test runner replacing legacy VSTest. Key differences:
dotnet run --project (preferred) or dotnet testOutputType=Exe (not Library)EnableMSTestRunner=true in .csprojAll 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.PlatformOutputType=Exe: Makes the test project executable (required for the new runner)Directory.Packages.props (see dotnet-centralized-packages skill)This repository has 4 test projects configured correctly:
tests/ClaudeStack.Web.Tests/ClaudeStack.Web.Tests.csprojtests/ClaudeStack.API.Tests/ClaudeStack.API.Tests.csprojtests/ClaudeStack.Web.Tests.Playwright/ClaudeStack.Web.Tests.Playwright.csprojtests/ClaudeStack.API.Tests.Playwright/ClaudeStack.API.Tests.Playwright.csprojAll follow the same configuration pattern.
The preferred way to run tests with Microsoft.Testing.Platform:
# Run all tests in a specific project
dotnet run --project tests/ClaudeStack.Web.Tests/ClaudeStack.Web.Tests.csproj
# Run all tests in a specific project (shorter path)
dotnet run --project tests/ClaudeStack.Web.Tests
# Run all tests in all projects (from solution root)
dotnet test
Use the --filter option to run specific tests:
# Run a specific test method
dotnet test --filter FullyQualifiedName~TestMethod1
# Run all tests in a class
dotnet test --filter FullyQualifiedName~ClaudeStack.Web.Tests.Test1
# Run tests matching a pattern
dotnet test --filter Name~Login
# Run tests by trait/category
dotnet test --filter TestCategory=Integration
# Navigate to test project
cd tests/ClaudeStack.Web.Tests
# Run tests
dotnet run
# Or use dotnet test
dotnet test
# From solution root, run all tests
dotnet test
This runs all 4 test projects sequentially.
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).
Standard MSTest attributes: [TestClass], [TestMethod], [TestInitialize], [TestCleanup]
Important: ImplicitUsings is disabled. Always include: using Microsoft.VisualStudio.TestTools.UnitTesting;
All test projects use method-level parallelization:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
This means test methods run in parallel within each test class.
Available options:
// Method-level: Test methods run in parallel (current setting)
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
// Class-level: Test classes run in parallel, methods sequential within class
[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]
Disable parallelization for specific tests:
[TestClass]
[DoNotParallelize]
public class SequentialTests
{
[TestMethod]
public void MustRunSequentially()
{
// This test class won't run in parallel with others
}
}
Use the .NET Core Test Explorer extension:
Not directly supported. Use IDE debugging instead.
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.
Use the DotNetCoreCLI@2 task:
- task: DotNetCoreCLI@2
displayName: 'Run Tests'
inputs:
command: 'test'
projects: '**/*.Tests.csproj'
arguments: '--configuration Release'
- name: Run Tests
run: dotnet test --configuration Release
# Generate TRX results
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).
Symptoms: Test project builds but tests don't execute
Solution: Verify project configuration:
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
Symptoms: dotnet test works but shows warnings or errors
Solution: Use dotnet run --project instead:
dotnet run --project tests/ClaudeStack.Web.Tests
Symptoms: After creating new test project, global.json is replaced
Cause: Using --test-runner flag with dotnet new mstest
Solution:
--test-runner flag when creating test projects in this repository# CORRECT
dotnet new mstest -o tests/NewProject
# WRONG - will overwrite global.json
dotnet new mstest -o tests/NewProject --test-runner Microsoft.Testing.Platform
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
Symptoms: Tests take longer than expected
Solution: Verify MSTestSettings.cs has parallelization:
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
Symptoms: Build errors about MSTest versions
Solution: Check Directory.Packages.props. Never add Version attribute to PackageReference in .csproj (see dotnet-centralized-packages skill).
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).
# Run tests in a project
dotnet run --project tests/ClaudeStack.Web.Tests
# Run all tests
dotnet test
# Run specific test
dotnet test --filter FullyQualifiedName~TestMethod1
# Run with detailed output
dotnet test --verbosity detailed
# Generate test results
dotnet test --logger "trx;LogFileName=results.trx"
<PropertyGroup>
<EnableMSTestRunner>true</EnableMSTestRunner>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" />
</ItemGroup>
Version managed in Directory.Packages.props.
using Microsoft.VisualStudio.TestTools.UnitTesting;
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace YourNamespace.Tests
{
[TestClass]
public class YourTests
{
[TestMethod]
public void YourTest()
{
// Arrange
var expected = true;
// Act
var actual = true;
// Assert
Assert.AreEqual(expected, actual);
}
}
}
# Step 1: Create project (DO NOT use --test-runner flag)
dotnet new mstest -o tests/NewProject
# Step 2: Manually add to .csproj
# <PropertyGroup>
# <EnableMSTestRunner>true</EnableMSTestRunner>
# <OutputType>Exe</OutputType>
# </PropertyGroup>
# Step 3: Add MSTestSettings.cs
# [assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
# Step 4: Add to solution
dotnet sln add tests/NewProject/NewProject.csproj
This skill is accurate as of .NET 10 RC 2. Some details may change in the RTM release.