Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Build extensions for Microsoft.Testing.Platform (MTP)
description: Learn how to create in-process and out-of-process extensions for Microsoft.Testing.Platform (MTP).
author: MarcoRossignoli
ms.author: mrossignoli
ms.date: 06/02/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand Down Expand Up @@ -206,43 +206,46 @@ If your extension requires intensive initialization and you need to use the asyn

### The `ITestApplicationLifecycleCallbacks` extensions

The `ITestApplicationLifecycleCallbacks` is an *in-process* extension that enables the execution of code before everything, it's like to have access to the first line of the hypothetical *main* of the *test host*.
> [!IMPORTANT]
> `ITestApplicationLifecycleCallbacks` was removed in MTP 2.0.0. Use `ITestHostApplicationLifetime` instead. For more information, see [Migrate from Microsoft.Testing.Platform (MTP) v1 to v2](microsoft-testing-platform-migration-from-v1-to-v2.md#removed-obsolete-types).

The `ITestHostApplicationLifetime` interface lets an *in-process* extension run code at the start and end of the *test host*.

To register a custom `ITestApplicationLifecycleCallbacks`, utilize the following api:
To register a custom `ITestHostApplicationLifetime`, use the following API:

```csharp
var builder = await TestApplication.CreateBuilderAsync(args);

// ...

builder.TestHost.AddTestApplicationLifecycleCallbacks(
builder.TestHost.AddTestHostApplicationLifetime(
static serviceProvider
=> new CustomTestApplicationLifecycleCallbacks());
=> new CustomTestHostApplicationLifetime());
```

The factory utilizes the [IServiceProvider](./microsoft-testing-platform-architecture-services.md#the-imessagebus-service) to gain access to the suite of services offered by the testing platform.
The factory uses the [IServiceProvider](./microsoft-testing-platform-architecture-services.md#the-imessagebus-service) to access the services offered by the testing platform.

> [!IMPORTANT]
> The sequence of registration is significant, as the APIs are called in the order they were registered.

The `ITestApplicationLifecycleCallbacks` interface includes the following methods:
The `ITestHostApplicationLifetime` interface includes the following methods:

```csharp
public interface ITestApplicationLifecycleCallbacks : ITestHostExtension
public interface ITestHostApplicationLifetime : ITestHostExtension
{
Task BeforeRunAsync(CancellationToken cancellationToken);

Task AfterRunAsync(
int exitCode,
CancellationToken cancellation);
CancellationToken cancellationToken);
}

public interface ITestHostExtension : IExtension
{
}
```

The `ITestApplicationLifecycleCallbacks` is a type of `ITestHostExtension`, which serves as a base for all *test host* extensions. Like all other extension points, it also inherits from [IExtension](./microsoft-testing-platform-architecture-test-framework.md#the-iextension-interface). Therefore, like any other extension, you can choose to enable or disable it using the `IExtension.IsEnabledAsync` API.
The `ITestHostApplicationLifetime` interface extends `ITestHostExtension`, which serves as a base for all *test host* extensions. Like all other extension points, it also inherits from [IExtension](./microsoft-testing-platform-architecture-test-framework.md#the-iextension-interface). Therefore, like any other extension, you can choose to enable or disable it using the `IExtension.IsEnabledAsync` API.

`BeforeRunAsync`: This method serves as the initial point of contact for the *test host* and is the first opportunity for an *in-process* extension to execute a feature. It's typically used to establish a connection with any corresponding *out-of-process* extensions if a feature is designed to operate across both environments.

Expand Down Expand Up @@ -492,7 +495,7 @@ Consider the following details for this API:

`OnTestHostProcessStartedAsync`: This method is invoked immediately after the test host starts. This method offers an object that implements the `ITestHostProcessInformation` interface, which provides key details about the test host process result.
> [!IMPORTANT]
> The invocation of this method does not halt the test host's execution. If you need to pause it, you should register an [*in-process*](./microsoft-testing-platform-architecture.md#in-process-vs-out-of-process-extensions) extension such as [`ITestApplicationLifecycleCallbacks`](#the-itestapplicationlifecyclecallbacks-extensions) and synchronize it with the *out-of-process* extension.
> The invocation of this method does not halt the test host's execution. If you need to pause it, you should register an [*in-process*](./microsoft-testing-platform-architecture.md#in-process-vs-out-of-process-extensions) extension such as [`ITestHostApplicationLifetime`](#the-itestapplicationlifecyclecallbacks-extensions) and synchronize it with the *out-of-process* extension.

`OnTestHostProcessExitedAsync`: This method is invoked when the test suite execution is complete. This method supplies an object that adheres to the `ITestHostProcessInformation` interface, which conveys crucial details about the outcome of the test host process.

Expand Down Expand Up @@ -595,18 +598,18 @@ The testing platform consists of a [testing framework](./microsoft-testing-platf

1. [ITestHostEnvironmentVariableProvider.UpdateAsync](#the-itesthostenvironmentvariableprovider-extensions) : Out-of-process
1. [ITestHostEnvironmentVariableProvider.ValidateTestHostEnvironmentVariablesAsync](#the-itesthostenvironmentvariableprovider-extensions) : Out-of-process
1. [ITestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync](#the-itestsessionlifetimehandler-extensions) : Out-of-process
1. [ITestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync](#the-itesthostprocesslifetimehandler-extensions) : Out-of-process
1. Test host process start
1. [ITestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync](#the-itestsessionlifetimehandler-extensions) : Out-of-process, this event can intertwine the actions of *in-process* extensions, depending on race conditions.
1. [ITestApplicationLifecycleCallbacks.BeforeRunAsync](#the-itestsessionlifetimehandler-extensions): In-process
1. [ITestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync](#the-itesthostprocesslifetimehandler-extensions) : Out-of-process, this event can intertwine the actions of *in-process* extensions, depending on race conditions.
1. [ITestHostApplicationLifetime.BeforeRunAsync](#the-itestapplicationlifecyclecallbacks-extensions): In-process
1. [ITestSessionLifetimeHandler.OnTestSessionStartingAsync](#the-itestsessionlifetimehandler-extensions): In-process
1. [ITestFramework.CreateTestSessionAsync](./microsoft-testing-platform-architecture-test-framework.md#test-framework-extension): In-process
1. [ITestFramework.ExecuteRequestAsync](./microsoft-testing-platform-architecture-test-framework.md#test-framework-extension): In-process, this method can be called one or more times. At this point, the testing framework will transmit information to the [IMessageBus](./microsoft-testing-platform-architecture-services.md#the-imessagebus-service) that can be utilized by the [IDataConsumer](#the-idataconsumer-extensions).
1. [ITestFramework.CloseTestSessionAsync](./microsoft-testing-platform-architecture-test-framework.md#test-framework-extension): In-process
1. [ITestSessionLifetimeHandler.OnTestSessionFinishingAsync](#the-itestsessionlifetimehandler-extensions): In-process
1. [ITestApplicationLifecycleCallbacks.AfterRunAsync](#the-itestsessionlifetimehandler-extensions): In-process
1. [ITestHostApplicationLifetime.AfterRunAsync](#the-itestapplicationlifecyclecallbacks-extensions): In-process
1. In-process cleanup, involves calling dispose and [IAsyncCleanableExtension](#asynchronous-initialization-and-cleanup-of-extensions) on all extension points.
1. [ITestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync](#the-itestsessionlifetimehandler-extensions) : Out-of-process
1. [ITestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync](#the-itesthostprocesslifetimehandler-extensions) : Out-of-process
1. Out-of-process cleanup, involves calling dispose and [IAsyncCleanableExtension](#asynchronous-initialization-and-cleanup-of-extensions) on all extension points.

## Extensions helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Microsoft.Testing.Platform (MTP) CLI options reference
description: Find platform and extension command-line options for MTP in one place.
author: Evangelink
ms.author: amauryleve
ms.date: 06/01/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand Down Expand Up @@ -68,6 +68,9 @@ This article gives a central entry point for MTP command-line options.

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 slows down the test execution.

> [!NOTE]
> Available in MTP starting with version 2.0.0. It replaces the previous `--diagnostic-filelogger-synchronouswrite` option, which was removed in MTP 2.0.0.

- **`--diagnostic-output-directory`**

The output directory of the diagnostic logging, if not specified the file is generated in the default _TestResults_ directory.
Expand All @@ -76,6 +79,9 @@ This article gives a central entry point for MTP command-line options.

The prefix for the log file name. Defaults to `"log"`.

> [!NOTE]
> Available in MTP starting with version 2.0.0. It replaces the previous `--diagnostic-output-fileprefix` option, which was removed in MTP 2.0.0.

- **`--diagnostic-verbosity`**

Defines the verbosity level when the `--diagnostic` switch is used. The available values are `Trace`, `Debug`, `Information`, `Warning`, `Error`, or `Critical`.
Expand Down
37 changes: 31 additions & 6 deletions docs/core/testing/microsoft-testing-platform-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Microsoft.Testing.Platform (MTP) config options
description: Learn how to configure MTP using testconfig.json configuration settings and environment variables.
author: Evangelink
ms.author: amauryleve
ms.date: 06/01/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand Down Expand Up @@ -78,9 +78,27 @@ Example:
}
```

### Extension options are CLI-only
### Environment variables in testconfig.json

Extension features such as [crash dump](microsoft-testing-platform-crash-hang-dumps.md), [hang dump](microsoft-testing-platform-crash-hang-dumps.md), [retry](microsoft-testing-platform-retry.md), [TRX reports](microsoft-testing-platform-test-reports.md), and [code coverage](microsoft-testing-platform-code-coverage.md) are **not** configurable via *testconfig.json*. These features are configured exclusively through command-line arguments.
> [!NOTE]
> Available in MTP starting with version 2.3.0.

The `environmentVariables` section sets environment variables for the test process before it starts. Use string values for each variable.

```json
{
"environmentVariables": {
"DOTNET_ENVIRONMENT": "Development",
"FEATURE_FLAG": "true"
}
}
```

### CLI options in testconfig.json

Before MTP 2.3.0, extension features such as [crash dump](microsoft-testing-platform-crash-hang-dumps.md), [hang dump](microsoft-testing-platform-crash-hang-dumps.md), [retry](microsoft-testing-platform-retry.md), [TRX reports](microsoft-testing-platform-test-reports.md), and [code coverage](microsoft-testing-platform-code-coverage.md) aren't configurable via *testconfig.json*. These features are configured exclusively through command-line arguments.

Starting with MTP 2.3.0, MTP can read CLI options from *testconfig.json* through `IConfiguration`. This support includes extension options, so you can use JSON entries for options that you don't want to pass on the command line each run. Command-line arguments still take precedence.

For a complete reference of command-line options, see [MTP CLI options reference](microsoft-testing-platform-cli-options.md).

Expand Down Expand Up @@ -128,9 +146,9 @@ If you're migrating from a *.runsettings* file, the following table maps common
| `RunConfiguration/MaxCpuCount` | No equivalent | Process-level parallelism is controlled by `dotnet test --max-parallel-test-modules` or MSBuild `/m` option. |
| `MSTest/*` | `mstest.*` | See [Configure MSTest — testconfig.json](unit-testing-mstest-configure.md#testconfigjson). |
| `xUnit/*` | `xUnit.*` | See [xUnit.net testconfig.json](https://xunit.net/docs/config-testconfig-json). |
| `LoggerRunSettings/Loggers` | CLI only | Use `--report-trx` or similar CLI options. |
| `DataCollectionRunSettings` (blame) | CLI only | Use `--crashdump` and `--hangdump` CLI options. See [Crash and hang dumps](microsoft-testing-platform-crash-hang-dumps.md). |
| `DataCollectionRunSettings` (coverage) | CLI only | Use `--coverage` CLI option. See [Code coverage](microsoft-testing-platform-code-coverage.md). |
| `LoggerRunSettings/Loggers` | CLI options | Use `--report-trx` or similar CLI options. Starting with MTP 2.3.0, MTP can read CLI options from *testconfig.json*. |
| `DataCollectionRunSettings` (blame) | CLI options | Use `--crashdump` and `--hangdump` CLI options. Starting with MTP 2.3.0, MTP can read CLI options from *testconfig.json*. See [Crash and hang dumps](microsoft-testing-platform-crash-hang-dumps.md). |
| `DataCollectionRunSettings` (coverage) | CLI options | Use `--coverage` CLI option. Starting with MTP 2.3.0, MTP can read CLI options from *testconfig.json*. See [Code coverage](microsoft-testing-platform-code-coverage.md). |
| `TestRunParameters` | `--test-parameter` CLI | Use `--test-parameter key=value` on the command line. |

## Environment variables
Expand Down Expand Up @@ -186,6 +204,13 @@ A semicolon-separated list of exit codes to ignore. When an exit code is ignored

When set to `1` or `true`, suppresses the startup banner, the copyright message, and the telemetry banner. Equivalent to the `--no-banner` command-line option. The `DOTNET_NOLOGO` environment variable has the same effect.

### `NO_COLOR` environment variable

When set to any non-empty value, suppresses all ANSI color output. MTP honors the [`NO_COLOR`](https://no-color.org/) convention.

> [!NOTE]
> Available in MTP starting with version 2.3.0.

### `DOTNET_NOLOGO` environment variable

When set to `1` or `true`, suppresses the startup banner, the copyright message, and the telemetry banner. This is the standard .NET CLI environment variable and is honored by MTP. See also `TESTINGPLATFORM_NOBANNER`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Microsoft.Testing.Platform (MTP) OpenTelemetry
description: Learn how to use the OpenTelemetry extension to emit traces and metrics from MTP.
author: Evangelink
ms.author: amauryleve
ms.date: 02/25/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand All @@ -13,6 +13,9 @@ This feature requires the [Microsoft.Testing.Extensions.OpenTelemetry](https://n

This extension integrates [OpenTelemetry](https://opentelemetry.io/) with Microsoft.Testing.Platform (MTP), allowing test runs to emit traces and metrics through the standard OpenTelemetry SDK.

> [!NOTE]
> This extension is available in MTP starting with version 2.1.0.

> [!IMPORTANT]
> This extension is currently experimental. All public APIs are gated behind the `TPEXP` diagnostic ID.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Run and debug tests with Microsoft.Testing.Platform (MTP)
description: Learn how to run and debug MTP test projects from CLI, Visual Studio, Visual Studio Code, and CI pipelines.
author: Evangelink
ms.author: amauryleve
ms.date: 02/24/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand All @@ -23,6 +23,11 @@ MTP test projects are built as executables that can be run (or debugged) directl
> [!IMPORTANT]
> By default, MTP collects telemetry. For more information and options on opting out, see [MTP telemetry](microsoft-testing-platform-telemetry.md).

> [!NOTE]
> Available in MTP starting with version 2.3.0.
>
> For a graceful stop, press <kbd>Ctrl</kbd>+<kbd>C</kbd> once to request cancellation. Running tests can finish teardown. To terminate immediately, press <kbd>Ctrl</kbd>+<kbd>C</kbd> again.

## [.NET CLI](#tab/dotnetcli)

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](../deploying/native-aot/index.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Microsoft.Testing.Platform (MTP) terminal output
description: Learn about the built-in terminal test reporter in MTP, including output modes, ANSI support, and progress indicators.
author: evangelink
ms.author: amauryleve
ms.date: 06/01/2026
ms.date: 06/16/2026
ai-usage: ai-assisted
---

Expand Down Expand Up @@ -45,9 +45,13 @@ The progress bar is written based on the selected mode:

| Option | Description |
|---|---|
| `--no-progress` | Disables reporting progress to screen. |
| `--no-progress` | Disables reporting progress to screen. Deprecated in MTP 2.3.0 in favor of `--progress off`. |
| `--progress` | Controls whether progress is shown. Valid values are `auto` (default), `on` (also accepts `true`, `enable`, `1`), and `off` (also accepts `false`, `disable`, `0`). Available in MTP starting with version 2.3.0. |
| `--no-ansi` | Disables outputting ANSI escape characters to screen. |
| `--ansi` | Controls whether ANSI escape characters are emitted. Valid values are `auto` (default), `on` (also accepts `true`, `enable`, `1`), and `off` (also accepts `false`, `disable`, `0`). Available in MTP starting with version 2.3.0. |
| `--output` | Specifies the output verbosity when reporting tests. Valid values are `Normal` and `Detailed`. Default is `Normal`. |
| `--show-stdout` | Determines when to show captured standard output of a test. Valid values are `All`, `Failed`, and `None`. Default is `All`. Available in MTP starting with version 2.2.1. |
| `--show-stderr` | Determines when to show captured error output of a test. Valid values are `All`, `Failed`, and `None`. Default is `All`. Available in MTP starting with version 2.2.1. |

> [!NOTE]
> Starting with MTP 2.3.0, when MTP detects that it runs inside an LLM or AI tool environment, it suppresses the startup banner and changes the default of `--show-stdout` and `--show-stderr` from `All` to `Failed` to reduce noise.
Loading
Loading