Skip to main content

Running your tests

As TUnit is built on-top of the newer Microsoft.Testing.Platform, and combined with the fact that TUnit tests are source generated, running your tests is available in a variety of ways.

Please note that for the coverage and trx report, you need to install additional extensions

dotnet run

For a simple execution of a project, dotnet run is the preferred method, allowing easier passing in of command line flags.

cd 'C:/Your/Test/Directory'
dotnet run -c Release
# or with flags
dotnet run -c Release --report-trx --coverage

dotnet test

dotnet test requires any command line flags to be specified as application arguments, meaning after a -- - Otherwise you'll get an error about unknown switches.

cd 'C:/Your/Test/Directory'
dotnet test -c Release
# or with flags
dotnet test -c Release -- --report-trx --coverage

dotnet exec

If your test project has already been built, you can use dotnet exec or just dotnet with the .dll path

cd 'C:/Your/Test/Directory/bin/Release/net8.0'
dotnet exec YourTestProject.dll
# or with flags
dotnet exec YourTestProject.dll --report-trx --coverage

or

cd 'C:/Your/Test/Directory/bin/Release/net8.0'
dotnet YourTestProject.dll
# or with flags
dotnet YourTestProject.dll --report-trx --coverage

Published Test Project

When you publish your test project, you'll be given an executable. On windows this'll be a .exe and on Linux/MacOS there'll be no extension.

This can be invoked directly and passed any flags.

cd 'C:/Your/Test/Directory/bin/Release/net8.0/win-x64/publish'
./YourTestProject.exe
# or with flags
./YourTestProject.exe --report-trx --coverage

IDE Support

Visual Studio

Visual Studio is supported. The "Use testing platform server mode" option must be selected in Tools > Manage Preview Features.

Visual Studio Settings

Rider

Rider is supported.

The Enable Testing Platform support option must be selected in Settings > Build, Execution, Deployment > Unit Testing > VSTest.

Rider Settings

VS Code

Visual Studio Code is supported.

  • Install the extension Name: C# Dev Kit
  • Go to the C# Dev Kit extension's settings
  • Enable Dotnet > Test Window > Use Testing Platform Protocol

Visual Studio Code Settings