Use static test splitting
Static test splitting reduces overall job time by dividing your tests across parallel execution nodes. It is built in to circleci testsuite run and is free, with no extra configuration in test-suites.yml.
How it works
When parallelism is set on your job, circleci testsuite run splits your tests across the parallel nodes up front, using the durations reported in your JUnit results from previous runs.
Because the split is assigned before the tests run, it cannot account for fixed costs such as runner startup and per-node setup. Nodes can still finish at noticeably different times. To keep nodes evenly loaded as they run, use Dynamic Test Splitting, which has a credit charge above your plan’s allowance.
Prerequisites
Before using static test splitting, ensure you have completed the Getting Started With Smarter Testing guide and have:
-
Configured your
.circleci/test-suites.ymlwithdiscoverandruncommands. -
Verified your tests run successfully with the
testsuitecommand. -
Added a
store_test_resultsstep to your job, so CircleCI has the JUnit timing data it uses to split your tests. See Upload Test Results.
1. Set parallelism on your job
Set parallelism to a value greater than 1 on the job that runs circleci testsuite run. See the Configuration Reference for more information.
jobs:
build-and-test:
parallelism: 4
# ...
steps:
- checkout
- run:
name: Run tests
command: circleci testsuite run "ci tests"
- store_test_results:
# Must match outputs.junit in test-suites.yml
path: test-reports
2. Verify the split
Commit your configuration to your feature branch and push to your VCS. Then verify that your tests are split across nodes by looking at the Timing tab in the UI:
-
Navigate to your pipeline in the CircleCI web app and open the test job.
-
Open the Timing tab.
-
Confirm that each parallel node ran a share of your tests.
The first run on a branch might split less evenly, because timing data from earlier runs is not yet available.
Next steps
-
Use Dynamic Test Splitting to evenly split tests across parallel nodes as they run.
-
Rerun Only Failed Tests to rerun only the tests that failed when you rerun a workflow from failed.
-
Set Parallelism Dynamically to set parallelism from a target duration for each node, instead of a fixed value.