A test command that never finishes can consume an Azure Pipelines agent until the job timeout kills it. A large solution can also keep running after enough failures have already made the result unusable, while several test applications may overwrite reports that share the same relative file name.
.NET 11 dotnet test in Azure Pipelines can put those controls at the test-run boundary. With Microsoft.Testing.Platform, --timeout and --maximum-failed-tests apply to the complete run, and --results-directory-layout per-module isolates each test application’s output. The safe pipeline pattern is to pin the prerequisites, preserve the distinct exit codes, publish diagnostics even after failure, and prove the policy on a non-production branch before rollout.
Table of Contents
Why multi-project test runs need a run-level boundary
A job-level timeout and a test-run timeout solve different problems. Azure Pipelines can stop the entire job after a configured duration, but that boundary also covers restore, build, test, artifact upload, and cleanup. If the job timeout fires, the steps that would publish logs or test output may never run.
The .NET 11 run-level options operate inside dotnet test. --timeout counts time while at least one test application is running. --maximum-failed-tests stops the complete run after the combined number of failed, errored, timed-out, or cancelled results reaches the limit. This is more useful than adding a separate timeout independently to every test project because the policy follows the complete solution run.
Keep the Azure Pipelines job timeout as an outer safety boundary. Set the test timeout shorter so the command can finish deliberately, return a meaningful exit code, and leave time for artifact publication.
Pin the .NET 11 and Microsoft.Testing.Platform prerequisites
The run-level switches described here require the Microsoft.Testing.Platform path for dotnet test. Microsoft documents --maximum-failed-tests for .NET 11 with Microsoft.Testing.Platform 2.4 or later. Do not add the switches to an existing pipeline and assume every test framework or older SDK will accept them.
variables:
DotNetSdkVersion: '11.0.x'
BuildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: Install pinned .NET SDK
inputs:
packageType: sdk
version: '$(DotNetSdkVersion)'
- bash: |
set -euo pipefail
dotnet --info
dotnet test --help | grep -- '--maximum-failed-tests'
dotnet test --help | grep -- '--results-directory-layout'
displayName: Verify test-run capabilities
The help check makes capability discovery explicit. It fails before the expensive test run if an agent resolves an older SDK or the repository is not using a compatible test platform. Commit global.json when the repository requires an exact SDK feature band; keep UseDotNet@2 aligned with that decision.
Configure .NET 11 dotnet test in Azure Pipelines
Place run-level options before --. Arguments after -- are forwarded to each test application instead of controlling the complete run.
- bash: |
set +e
dotnet test MyProduct.sln \
--no-restore \
--configuration '$(BuildConfiguration)' \
--timeout 20m \
--maximum-failed-tests 5 \
--results-directory '$(Agent.TempDirectory)/test-results' \
--results-directory-layout per-module
test_exit_code=$?
echo "##vso[task.setvariable variable=TestExitCode]$test_exit_code"
case "$test_exit_code" in
0)
echo "Test run completed successfully."
;;
3)
echo "##vso[task.logissue type=error]The complete test run reached its 20-minute timeout."
;;
13)
echo "##vso[task.logissue type=error]The complete test run reached the five-result failure limit."
;;
*)
echo "##vso[task.logissue type=error]dotnet test failed with exit code $test_exit_code."
;;
esac
exit "$test_exit_code"
displayName: Run bounded .NET tests
timeoutInMinutes: 25
The step timeout is intentionally longer than the test timeout. That five-minute gap is not a performance target; it is space for startup, orderly cancellation, result flushing, and command shutdown. The outer job timeout should be longer again so later condition: always() steps can run.
Preserve exit codes 3 and 13
.NET 11 gives the two policies distinct outcomes: a run-level timeout returns exit code 3, while reaching --maximum-failed-tests returns exit code 13. Preserve those values instead of replacing every non-zero result with a generic success or a single custom code.
- Exit 0: the bounded run completed successfully.
- Exit 3: investigate a slow, hung, or blocked test path and review the last active module.
- Exit 13: the failure budget was exhausted; start with the first failures rather than assuming remaining projects passed.
- Any other non-zero code: retain the normal
dotnet testfailure semantics and inspect the command output.
Do not mark the test step successful merely to keep artifact publication alive. Azure Pipelines supports follow-up steps with condition: always(); use that mechanism so the job remains failed while diagnostics are still preserved.
Keep every module’s test output
Multi-targeted solutions and repositories with repeated test-project names can emit reports or diagnostics with identical relative paths. The default result layout remains flat. In .NET 11 RC1, --results-directory-layout per-module gives every test application a separate directory under the selected results root.
$(Agent.TempDirectory)/test-results/
Api.Tests/
net11.0_x64/
Application.Tests/
net11.0_x64/
Storage.Tests/
net11.0_x64/
Treat the directory structure as a contract. Before rollout, list the result tree and confirm that each expected module and target framework has its own location. A per-module directory prevents path collisions; it does not guarantee that every test application produced every desired reporter artifact. Configure and verify the relevant Microsoft.Testing.Platform reporting extensions separately.
Publish diagnostics after a failed test step
Publish the complete result root even when the test command fails. This preserves logs from modules that completed before the timeout or failure limit, plus any diagnostics produced during orderly cancellation.
- task: PublishPipelineArtifact@1
displayName: Publish bounded test outputs
condition: always()
inputs:
targetPath: '$(Agent.TempDirectory)/test-results'
artifact: 'test-results-$(System.JobAttempt)'
publishLocation: pipeline
- bash: |
echo "dotnet test exit code: $(TestExitCode)"
find '$(Agent.TempDirectory)/test-results' -maxdepth 4 -type f -print || true
displayName: Summarize preserved test outputs
condition: always()
Include $(System.JobAttempt) or another retry identifier in the artifact name. Otherwise a retried job can make it difficult to distinguish the original failure evidence from the later attempt.
Validate the policy before rollout
Test the pipeline controls with deliberate, temporary cases on a branch. Do not first discover their behavior during a production release.
- Run a small passing solution and confirm exit code 0 plus one result directory per module.
- Add a cancellable test whose duration exceeds a short branch-only timeout. Confirm exit code 3 and verify that the artifact step still executes.
- Add more known failing tests than the branch-only limit. Confirm exit code 13 and check that unexecuted tests are not presented as passed.
- Run the real solution with the intended limits and compare duration, artifact count, and module list with the current pipeline.
- Remove the deliberate failure and timeout fixtures before merging the policy change.
Use a generous first production limit based on recent successful runs. Tighten it only after observing normal variation. A failure cap of one may be appropriate for a fast deterministic suite but can hide useful independent failures in a large repository.
Production risks and edge cases
- Framework capability: the maximum-failure policy depends on test-platform capability support. Verify the actual repository stack instead of relying only on the installed SDK.
- Cancellation behavior: tests that ignore cancellation or block native code can delay shutdown. Keep the Azure Pipelines step and job timeouts as outer boundaries.
- Partial evidence: a stopped run is incomplete by definition. Dashboards must not interpret missing tests as successful tests.
- Parallel execution: several failures can complete near the same time, so the observed total may cross the configured threshold before every application stops.
- Reporter configuration: an isolated output directory does not enable TRX, coverage, or dump collection by itself.
- Rollback: remove the three run-level options to restore the previous command, but keep the always-run artifact step if it improves failure diagnosis.
The useful outcome of .NET 11 dotnet test in Azure Pipelines is not simply a shorter pipeline. It is a bounded test run that fails honestly, explains whether time or failures stopped it, and leaves enough evidence for the next action.
References
- .NET SDK in .NET 11 RC1 — release notes
- Microsoft Learn — dotnet test with Microsoft.Testing.Platform
- dotnet/sdk #55458 — run-level test controls
- dotnet/sdk #55475 — per-module result layout
- Microsoft Learn — UseDotNet@2 task
- Microsoft Learn — Azure Pipelines conditions
Found this useful? Support more practical developer content.