Free tools

Test Shard Balancer: Split CI Tests by Duration

Split tests or spec files into CI shards that finish at about the same time, from a test report or a list of durations.

Runs in your browserNothing is uploadedNo sign-up

One "name,seconds" line per test or file (a header row is fine, "900ms" works), or paste or drop JUnit, TRX, NUnit, Playwright JSON or CTRF reports.

Or drop files on the box. Nothing is uploaded.

How the balancer splits

Give it test durations, either a name,seconds list or test reports from a previous run, and a shard count. It sorts the items from longest to shortest and gives each one to the shard with the least time so far. This rule, longest processing time first, is a classic scheduling result: Graham proved in 1969 that its longest shard is never more than 4/3 of the best possible split, and in practice it lands within a few percent.

Next to it the balancer shows the split you get without timing data: consecutive chunks with the same number of tests each. When a few files are much slower than the rest, that split leaves one shard running long after the others have finished, and your CI job takes as long as its slowest shard.

The results:

  • Longest shard: the wall-clock time of the job with this split.
  • Split by count: the same for the naive split, and the time saved.
  • Best possible: the larger of total time divided by the shard count and the longest single item. No split beats it.
  • How many shards pay off: the longest shard for each shard count. Once it stops falling, extra shards add machine time and setup without finishing sooner.

If one file takes longer than a fair share, the balancer says so: that file sets the floor, and the fix is to split it, not to add shards.

Getting durations

From a report, drop JUnit, TRX, NUnit, Playwright JSON or CTRF files from a recent full run and choose what a shard gets: whole files, suites or classes, or single tests. Pick what your runner can actually shard.

RunnerHow it splitsWhat to balance
Playwrightnpx playwright test --shard=1/4 splits by test file, or by single test when fullyParallel is onFiles, or single tests with fullyParallel
pytest with pytest-splitpytest --store-durations once, then pytest --splits 3 --group 1 on each shardSingle tests
CircleCIcircleci tests run (or circleci tests split on Server) with --split-by=timings, using timing data from the previous run's JUnit XMLFiles or class names

Playwright's own split does not use durations, so balanced shards there mean passing each shard its own list of files with --test-list, which the Copy button's one-path-per-line format fits. The sharded Playwright reports guide shows how to get one JSON report from a sharded run and wire the lists into a GitHub Actions matrix. pytest-split's least_duration algorithm uses the same idea as this page, assigning each test to the group with the least time so far, though it walks the tests in their own order rather than sorted longest first.

Sources

Get new posts by email.

Occasional email with new Testland posts and plugin releases.

Unsubscribe any time. Privacy policy