How to Run dotnet Tests in Parallel in CI
xUnit parallelizes test collections within an assembly, and you can shard assemblies across jobs with dotnet test filters.
Enable collection parallelism in xUnit config, then split coarse groups across CI jobs using dotnet test --filter by category or namespace.
xUnit config
xunit.runner.json
{
"parallelizeTestCollections": true,
"maxParallelThreads": 0
}Workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
category: [Unit, Integration, Contract]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
- run: dotnet test --filter "Category=${{ matrix.category }}"Gotchas
maxParallelThreads: 0uses the machine core count; set a number to cap it.- Tests in the same collection do not run in parallel with each other by design.
Related guides
How to Run Maven and Gradle Tests in ParallelParallelize JVM tests with Maven Surefire forkCount and Gradle --parallel plus maxParallelForks, using multip…
How to Run Rust Tests in Parallel With nextestRun Rust tests faster in CI with cargo-nextest, which executes each test in its own process and supports part…