Testing¶
- API Testing with Aspire: test API endpoints with an AppHost.
- Web Testing with Playwright: test browser flows and collect coverage.
- Integration Test Environment Variables: provide pipeline settings and secrets to .NET or TypeScript tests.
- Identity testing: create tokens and non-production test users.
Aspire integration test packages¶
API and web integration test projects start an AppHost with Aspire's DistributedApplicationTestingBuilder. Both reference these packages, with versions pinned centrally in Directory.Packages.props:
<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:
Run generated test projects with a named selector rather than a bare positional project path:
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 and VSTest target troubleshooting 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, which instruments the test process without adding a coverage package to the test project:
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. Missing central pins cause restore errors; a VSTest runner does not satisfy the native MTP configuration.