---
title: Testing
description: Run generated Forge tests and add API or browser integration coverage.
---

# Testing

- [API Testing with Aspire](api-integration-testing.md): test API endpoints with an AppHost.
- [Web Testing with Playwright](web-integration-testing.md): test browser flows and collect coverage.
- [Integration Test Environment Variables](integration-test-environment-variables.md): provide pipeline settings and secrets to .NET or TypeScript tests.
- [Identity testing](../identity/index.md#testing-development): create tokens and non-production test users.

## Aspire integration test packages

API and web integration test projects start an AppHost with Aspire's [`DistributedApplicationTestingBuilder`](https://learn.microsoft.com/en-us/dotnet/aspire/testing/overview). Both reference these packages, with versions pinned centrally in `Directory.Packages.props`:

```xml
<PackageReference Include="Aspire.Hosting.Testing" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
<PackageReference Include="xunit.v3" />
```

Each testing guide lists the extra packages its test type needs.

## Test Execution: Native Microsoft Testing Platform (MTP)

`saif-feature-base` generates a repository-root `global.json` that selects xUnit.net v3's native Microsoft Testing Platform mode:

```json
{
  "test": {
    "runner": "Microsoft.Testing.Platform"
  }
}
```

Run generated test projects with a named selector rather than a bare positional project path:

```powershell
dotnet test --project .\src\MyApp.IntegrationTests\MyApp.IntegrationTests.csproj --report-trx
```

Native MTP on .NET 10 uses `--project`, `--solution`, or `--test-modules` selectors. `--report-trx` requires `Microsoft.Testing.Extensions.TrxReport`, which the generated test projects reference. See Microsoft's [MTP runner guidance](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-with-dotnet-test#mtp-mode-of-dotnet-test) and [VSTest target troubleshooting](../../troubleshoot/vstest-target-not-supported-dotnet-10.md) if an older runner configuration fails.

Do not add `xunit.runner.visualstudio` to this native-MTP setup. It is the VSTest adapter, and xunit.v3 4.x no longer supports that bridge.

### Coverage

Collect coverage with [`dotnet-coverage`](https://learn.microsoft.com/dotnet/core/additional-tools/dotnet-coverage), which instruments the test process without adding a coverage package to the test project:

```powershell
dotnet-coverage collect --output coverage.cobertura.xml --output-format cobertura dotnet test --project .\src\MyApp.IntegrationTests\MyApp.IntegrationTests.csproj
```

### Adding tests to an older application

`saif-feature-api` assumes the application's central `Directory.Packages.props` already pins all its package references, including `xunit.v3` 4.x and `Microsoft.Testing.Extensions.TrxReport`. Before applying the add-on to an older application, compare its central package file and `global.json` with the current [`saif-feature-base` template](https://github.com/saif-corp/forge/tree/main/src/templates/saif-feature-base). Missing central pins cause restore errors; a VSTest runner does not satisfy the native MTP configuration.
