Skip to content
Latchkey

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: 0 uses 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

Run this faster and cheaper on Latchkey managed runners. Start free →