A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-intro below:

Microsoft.Testing.Platform overview - .NET | Microsoft Learn

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 Test 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.

Microsoft.Testing.Platform pillars

This new testing platform is built on the .NET Developer Experience Testing team's experience and aims to address the challenges encountered since the release of .NET Core in 2016. While there's a high level of compatibility between the .NET Framework and the .NET Core/.NET, some key features like the plugin-system and the new possible form factors of .NET compilations have made it complex to evolve or fully support the new runtime feature with the current VSTest platform architecture.

The main driving factors for the evolution of the new testing platform are detailed in the following:

Supported test frameworks 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, which is typical for most executables. For more information on the known exit codes, see Microsoft.Testing.Platform exit codes.

Tip

You can ignore a specific exit code using the --ignore-exit-code command line option.

You can also set command line options that apply to a specific test project in the project file using the TestingPlatformCommandLineArguments MSBuild property. One common use case is for test projects that have all the tests ignored, which will normally exit with exit code 8 (the test session ran zero tests). In this scenario, you can add the following under a PropertyGroup in your project file:

<TestingPlatformCommandLineArguments>$(TestingPlatformCommandLineArguments) --ignore-exit-code 8</TestingPlatformCommandLineArguments>

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

The Microsoft.Testing.Platform tests can be run (and debugged) in Visual Studio, they integrate with Test Explorer, and can also be run directly as startup project.

Run the app with Visual Studio

Microsoft.Testing.Platform test project are built as executables, and can be run directly. This runs all the tests in the given executable, unless a filter is provided.

  1. Navigate the test project you want to run in Solution Explorer, right select it and select Set as Startup Project.
  2. Select Debug > Start without Debugging (or use Ctrl+F5) to run the selected test project.

Console window pops up with the execution and summary of your test run.

Debug the app directly in Visual Studio

Microsoft.Testing.Platform test project can be debugged directly. To debug all the tests in the given executable, unless a filter is provided:

  1. Navigate the test project you want to run in Solution Explorer, right select it and select Set as Startup Project.
  2. Set breakpoint into the test that you'd like to debug.
  3. Go to Debug > Start Debugging (or press F5) to debug the selected test project.

All tests are executed until your test with a breakpoint is reached. Step through your test to debug it. Once you're done debugging the app resumes running all remaining tests, unless you stop it.

Use Test Explorer

To run a test, navigate to Test Explorer, select the test (or tests) to run. Right select it, and choose Run. Similarly to debug a test, select the test (or tests) in Test Explorer, right select and choose Debug.

Note

Automatic update of tests without building the project isn't available.

The C# extension along with C# Dev Kit allows you to debug/run tests in Visual Studio code, as well as adds integration with Visual Studio Code's Test Explorer.

Run the app with Visual Studio Code

Microsoft.Testing.Platform test project are built as executables, and can be run directly. This runs all the tests in the given executable, unless a filter is provided.

  1. Navigate to a test file that you want to run tests for.
  2. Use Ctrl+F5 to run the selected test project. If you have multiple projects a popup will ask you to select the one to run.

Console window pops up with the execution and summary of your test run.

Debug the app directly in Visual Studio Code

Microsoft.Testing.Platform test project are built as executables, and can be run directly. This runs all the tests in the given executable, unless a filter is provided.

  1. Navigate to a test file that you want to run tests for.
  2. Use F5 to debug the selected test project. If you have multiple projects a popup will ask you to select the one to run.

Tip

There are several other ways to run a dotnet project using C# DevKit, such as running from solution explorer or creating corresponding launch configurations. These are specified in the Visual Studio Code documentation.

As the project is run the output tab pops up with the execution and summary of your test run.

Use Test Explorer

To run a test, navigate to Test Explorer, select the test (or tests) to run. Right select it, and choose Run. Similarly to debug a test, select the test (or tests) in Test Explorer, right select and choose Debug.

Note

Automatic update of tests without building the project isn't available.

There's no special pipeline task, or any extra tooling to run Testing.Platform tests. There's also no other tooling required to run multiple tests projects through a single command.

To run a test project in CI add one step for each test executable that you wish to run, such as this on Azure DevOps:

- task: CmdLine@2
  displayName: "Run Contoso.MyTests"
  inputs:
    script: '.\Contoso.MyTests\bin\Debug\net8.0\Contoso.MyTests.exe'
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.

MSBuild integration

The NuGet package Microsoft.Testing.Platform.MSBuild provides various integrations for Microsoft.Testing.Platform with MSBuild:

Note

This integration works in a transitive way (a project that references another project referencing this package will behave as if it references the package) and can be disabled through the IsTestingPlatformApplication MSBuild property.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4