How to Run Tests Using Dotnet Test in .NET 10

Set up a modern testing environment with MicrosoftTestingPlatform (MTP), .NET 10, and dotnet test. Follow this guide to create and run tests, leveraging MTP’s executable runner and .NET 10’s performance.

Ashley Goolam

Ashley Goolam

27 August 2025

How to Run Tests Using Dotnet Test in .NET 10

Hey there, .NET developers! Ready to level up your testing game with the Microsoft Testing Platform (MTP) and .NET 10? If you’ve been using dotnet test with the traditional VSTest runner, buckle up—MTP is here to make your testing smoother, faster, and more flexible. In this conversational guide, we’ll explore what MTP, aka MicrosoftTestingPlatform, is, why it’s a step up from VSTest, and how to harness it with dotnet test in .NET 10 to build robust tests for your projects. I’ll walk you through the steps I took to experiment with this setup, from a basic MSTest project to a multi-project solution with a standalone executable. Let’s dive into the world of MTP, MicrosoftTestingPlatform, .NET 10, dotnet test and make testing easier and more fun!

💡
Want a great API Testing tool that generates beautiful API Documentation?

Want an integrated, All-in-One platform for your Developer Team to work together with maximum productivity?

Apidog delivers all your demands, and replaces Postman at a much more affordable price!
button

Why Does Testing Matter in .NET Development

Before we get our hands dirty, let’s talk about why testing is a big deal. Whether you’re building a small app or a massive enterprise system, tests ensure your code works as expected, catches bugs early, and saves you from those late-night debugging sessions. Automated unit tests, like those we’ll create with MSTest and MTP, let you verify functionality, improve code quality, and make refactoring a breeze. With .NET 10’s performance boosts and MTP’s modern testing framework, you’re set to write tests that are fast, reliable, and easy to integrate into CI/CD pipelines. Ready to see how? Let’s follow my journey!

What Is the Microsoft Testing Platform (MTP)?

The Microsoft Testing Platform (MTP), or MicrosoftTestingPlatform, is Microsoft’s next-generation testing framework, introduced to replace the aging VSTest runner. Unlike VSTest, which relies on complex adapters and DLL-based execution, MTP offers a streamlined, native experience for running tests in .NET. It’s built into .NET 10, making it faster and more flexible, with features like standalone executable test runners and better integration with dotnet test. MTP supports MSTest, NUnit, and xUnit, and it’s designed for modern workflows, including CI/CD and cross-platform development. You can think of it as VSTest’s cooler, more efficient sibling, optimized for .NET 10’s performance enhancements.

Step 1: Setting Up a Basic MSTest Project with MTP

Let’s start simple by creating a basic MSTest project to see MTP in action. Here’s how I kicked things off:

Create the Project:

dotnet new mstest -n MyMtpTests

Check the Project File:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
    <PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
  </ItemGroup>
</Project>

Run the Tests:

cd MyMtpTests
dotnet test
vstest runner

What’s Happening? This is a traditional setup using VSTest, but it’s a solid baseline before we upgrade to MTP. The project runs tests as a DLL, which is fine but not as flexible as MTP’s executable approach.

Step 2: Evolving to an MTP Executable-Based Test Runner

Now, let’s make things more exciting by switching to MTP’s standalone executable runner, which lets you run tests without dotnet test. Here’s how I did it:

Update the Project File:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <!-- Enable MTP runner and executable output -->
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
    <PackageReference Include="MSTest.TestFramework" Version="3.10.2" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.10.2" />
  </ItemGroup>
  <ItemGroup>
    <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
  </ItemGroup>
</Project>

Key changes:

Build the Project:

dotnet build
exe file generated

Run the Executable:

cd bin/Debug/net8.0
run test on .exe file

Why This Rocks: The executable approach is perfect for custom CI/CD setups or environments without the .NET SDK installed. It’s a game-changer for flexibility, and MTP makes it faster than VSTest by reducing overhead.

Step 3: Going Pro with .NET 10 and Multi-Project Testing

To see MTP and .NET 10 shine in a real-world scenario, let’s build a multi-project solution with a class library and tests. Here’s how I set it up:

Final Project structure:

MyMtpSolution/
│
├── MyLibrary/
│   ├── Calculator.cs
│   └── MyLibrary.csproj
│
├── MyLibrary.Tests/
│   ├── CalculatorTests.cs
│   └── MyLibrary.Tests.csproj
│
├── MyMtpSolution.sln
└── dotnet.config

1. Create a Solution:

dotnet new sln -n MyMtpSolution

2. Create a Class Library:

dotnet new classlib -n MyLibrary
namespace MyLibrary
{
    public class Calculator
    {
        public int Add(int a, int b) => a + b;
        public int Subtract(int a, int b) => a - b;
        public int Multiply(int a, int b) => a * b;
        public int Divide(int a, int b) => 
            b == 0 ? throw new ArgumentException("Cannot divide by zero.") : a / b;
    }
}

3. Create a Test Project:

dotnet new mstest -n MyLibrary.Tests
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyLibrary;

namespace MyLibrary.Tests
{
    [TestClass]
    public class CalculatorTests
    {
        private Calculator _calculator;

        [TestInitialize]
        public void Setup()
        {
            _calculator = new Calculator();
        }

        [TestMethod]
        public void Add_ReturnsCorrectSum()
        {
            Assert.AreEqual(5, _calculator.Add(2, 3));
        }

        [TestMethod]
        public void Subtract_ReturnsCorrectDifference()
        {
            Assert.AreEqual(1, _calculator.Subtract(3, 2));
        }

        [TestMethod]
        public void Multiply_ReturnsCorrectProduct()
        {
            Assert.AreEqual(6, _calculator.Multiply(2, 3));
        }

        [TestMethod]
        public void Divide_ReturnsCorrectQuotient()
        {
            Assert.AreEqual(2, _calculator.Divide(6, 3));
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void Divide_ByZero_ThrowsException()
        {
            _calculator.Divide(6, 0);
        }
    }
}

4. Add Project References:

dotnet add MyLibrary.Tests reference MyLibrary

5. Add Projects to Solution:

dotnet sln MyMtpSolution.sln add MyLibrary/MyLibrary.csproj
dotnet sln MyMtpSolution.sln add MyLibrary.Tests/MyLibrary.Tests.csproj

6. Configure for MTP:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
    <EnableMSTestRunner>true</EnableMSTestRunner>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="coverlet.collector" Version="6.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
    <PackageReference Include="MSTest.TestFramework" Version="3.10.2" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.10.2" />
  </ItemGroup>
  <ItemGroup>
    <Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
  </ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

7. Upgrade to .NET 10:

download .net10
<TargetFramework>net10.0</TargetFramework>

8. Create a dotnet.config File:

[dotnet.test.runner]
name = "Microsoft.Testing.Platform"

9. Build and Run Tests:

dotnet test
running the tests

Why This Is Awesome: .NET 10 brings performance improvements (faster JIT, better memory management), and MTP’s native integration eliminates VSTest’s legacy bridges, making tests faster and more reliable. The multi-project setup mimics real-world apps, with a library and separate test project.

How .NET 10 and MTP Improve Testing

MTP and .NET 10 take testing to the next level:

Users are buzzing about MTP: “It’s like VSTest but without the baggage—faster and cleaner!” With .NET 10, you get cutting-edge performance, and MTP makes dotnet test a joy.

Troubleshooting Tips

Conclusion

You’re now a pro at using MTP (MicrosoftTestingPlatform), .NET 10, dotnet test to build a modern testing setup! From a basic MSTest project to a multi-project solution with a standalone executable, you’ve seen how MTP outshines VSTest and how .NET 10 boosts performance. Try adding more tests, integrating into your CI/CD pipeline, or exploring MTP’s advanced features like parallel execution. Got cool test setups? Share them—let’s keep the testing vibes going!

button

Explore more

Top 10 Causes for Flaky Tests(Solutions Included)

Top 10 Causes for Flaky Tests(Solutions Included)

Discover the top 10 causes of flaky tests, from race conditions to external dependencies, and learn practical strategies to fix them for good.

26 August 2025

How to Use Postman Offline

How to Use Postman Offline

Postman’s offline mode helps developers continue API work without internet access. This guide explains how to use Postman offline, its key capabilities, and limitations, plus strategies to stay productive when working in disconnected environments.

26 August 2025

What Is a Wrapper in Programming?

What Is a Wrapper in Programming?

What is a wrapper in programming? Discover how wrappers simplify code, APIs, and legacy systems.

26 August 2025

Practice API Design-first in Apidog

Discover an easier way to build and use APIs