How do you shard and parallelise a long test suite?
AdvancedConceptTesting and Quality Gates
Answer
Split tests across N runners using timing data so shards finish around the same time, rather than splitting by file count. Playwright has --shard=1/4, Jest has --shard, pytest uses pytest-xdist (-n auto) within a machine and pytest-split across machines, GitLab uses parallel: with CI_NODE_INDEX. Ensure tests are isolated (no shared database rows), merge coverage and JUnit reports from all shards afterwards.
strategy:
matrix: { shard: [1, 2, 3, 4] }
steps:
- run: npx playwright test --shard=${{ matrix.shard }}/4
More on Testing and Quality Gates
What is the testing pyramid?BeginnerWhat is the difference between unit, integration, and end-to-end tests?BeginnerWhat are smoke tests and sanity tests in a deployment pipeline?IntermediateWhat is code coverage and is a high percentage a good target?IntermediateWhat is a quality gate in SonarQube?IntermediateHow do you integrate SonarQube into a CI pipeline and make it block on gate failure?Intermediate