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:
-
Verified your tests run successfully with the
testsuitecommand. -
Uploaded your test results, so CircleCI has the JUnit timing data it uses to split your tests:
-
If you are using the built-in test suite (using
circleci testsuite runwithout atest-suites.ymlfile) your test results are uploaded to CircleCI automatically because thestore-test-resultsoption is enabled. -
If you are maintaining your own
test-suites.ymlfile, set thestore-test-resultsconfig option totrueor add astore_test_resultsstep to your pipeline configuration. See the Testsuite Configuration Reference and the Upload Test Results guide.
-
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"
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.