Microsoft.Testing.Platform overview
Microsoft.Testing.Platform is a lightweight and portable alternative to VSTest for running tests in all contexts, including continuous integration (CI) pipelines, CLI, Visual Studio Test Explorer, and VS Code Text Explorer. The Microsoft.Testing.Platform is embedded directly in your test projects, and there's no other app dependencies, such as vstest.console
or dotnet test
needed to run your tests.
Microsoft.Testing.Platform
is open source. You can find Microsoft.Testing.Platform
code in microsoft/testfx GitHub repository.
Supported test frameworks
- MSTest. In MSTest, the support of
Microsoft.Testing.Platform
is done via MSTest runner. - NUnit: work in progress, for more information, see Microsoft Testing Platform for NUnit.
- xUnit: work in progress, for more information, see Microsoft Testing Platform for xUnit.
Run and debug tests
Microsoft.Testing.Platform
test projects are built as executables that can be run (or debugged) directly. There's no extra test running console or command. The app exits with a nonzero exit code if there's an error, as typical with most executables. For more information on the known exit codes, see Microsoft.Testing.Platform exit codes.
Important
By default, Microsoft.Testing.Platform
collects telemetry. For more information and options on opting out, see Microsoft.Testing.Platform telemetry.
Publishing the test project using dotnet publish
and running the app directly is another way to run your tests. For example, executing the ./Contoso.MyTests.exe
. In some scenarios it's also viable to use dotnet build
to produce the executable, but there can be edge cases to consider, such Native AOT.
Use dotnet run
The dotnet run
command can be used to build and run your test project. This is the easiest, although sometimes slowest, way to run your tests. Using dotnet run
is practical when you're editing and running tests locally, because it ensures that the test project is rebuilt when needed. dotnet run
will also automatically find the project in the current folder.
dotnet run --project Contoso.MyTests
For more information on dotnet run
, see dotnet run.
Use dotnet exec
The dotnet exec
or dotnet
command is used to execute (or run) an already built test project, this is an alternative to running the application directly. dotnet exec
requires path to the built test project dll.
dotnet exec Contoso.MyTests.dll
or
dotnet Contoso.MyTests.dll
Note
Providing the path to the test project executable (*.exe) results in an error:
Error:
An assembly specified in the application dependencies manifest
(Contoso.MyTests.deps.json) has already been found but with a different
file extension:
package: 'Contoso.MyTests', version: '1.0.0'
path: 'Contoso.MyTests.dll'
previously found assembly: 'S:\t\Contoso.MyTests\bin\Debug\net8.0\Contoso.MyTests.exe'
For more information on dotnet exec
, see dotnet exec.
Use dotnet test
Microsoft.Testing.Platform
offers a compatibility layer with vstest.console.exe
and dotnet test
ensuring you can run your tests as before while enabling new execution scenario.
dotnet test Contoso.MyTests.dll
Options
The list below described only the platform options. To see the specific options brought by each extension, either refer to the extension documentation page or use the --help
option.
--diagnostic
Enables the diagnostic logging. The default log level is Trace
. The file is written in the output directory with the following name format, log_[MMddHHssfff].diag
.
--diagnostic-filelogger-synchronouswrite
Forces the built-in file logger to synchronously write logs. Useful for scenarios where you don't want to lose any log entries (if the process crashes). This does slow down the test execution.
--diagnostic-output-directory
The output directory of the diagnostic logging, if not specified the file is generated in the default TestResults directory.
--diagnostic-output-fileprefix
The prefix for the log file name. Defaults to "log_"
.
--diagnostic-verbosity
Defines the verbosity level when the --diagnostic
switch is used. The available values are Trace
, Debug
, Information
, Warning
, Error
, or Critical
.
--help
Prints out a description of how to use the command.
-ignore-exit-code
Allows some non-zero exit codes to be ignored, and instead returned as 0
. For more information, see Ignore specific exit codes.
--info
Displays advanced information about the .NET Test Application such as:
- The platform.
- The environment.
- Each registered command line provider, such as its,
name
,version
,description
andoptions
. - Each registered tool, such as its,
command
,name
,version
,description
, and all command line providers.
This feature is used to understand extensions that would be registering the same command line option or the changes in available options between multiple versions of an extension (or the platform).
--list-tests
List available tests. Tests will not be executed.
--minimum-expected-tests
Specifies the minimum number of tests that are expected to run. By default, at least one test is expected to run.
--results-directory
The directory where the test results are going to be placed. If the specified directory doesn't exist, it's created. The default is TestResults
in the directory that contains the test application.
See also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for