<section class="blog-post-content lb-rtxt"><table id="amazon-polly-audio-table"><tbody><tr><td id="amazon-polly-audio-tab"><p></p></td></tr></tbody></table><p>I’m excited to announce that <a href="https://aws.amazon.com/codebuild/">AWS CodeBuild</a> now supports parallel test execution, so you can run your test suites concurrently and reduce build times significantly.</p><p>With <a href="https://github.com/sebsto/aws-codebuild-parallel-testing">the demo project I wrote for this post</a>, the total test time went down from 35 minutes to 6 minutes, including the time to provision the environments. These two screenshots from the <a href="https://aws.amazon.com/console/">AWS Management Console</a> show the difference.</p><p><strong>Sequential execution of the test suite</strong></p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/25/2025-03-24_18-19-55.png"><img class="aligncenter wp-image-94688" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/25/2025-03-24_18-19-55.png" alt="CodeBuild Parallel Test Results" width="800" height="181" /></a></p><p><strong>Parallel execution of the test suite</strong></p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/25/2025-03-24_18-18-26.png"><img class="aligncenter wp-image-94689" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/25/2025-03-24_18-18-26.png" alt="CodeBuild Parallel Test Results" width="800" height="181" /></a></p><p>Very long test times pose a significant challenge when running <a href="https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html#continuous_integration">continuous integration (CI)</a> at scale. As projects grow in complexity and team size, the time required to execute comprehensive test suites can increase dramatically, leading to extended pipeline execution times. This not only delays the delivery of new features and bug fixes, but also hampers developer productivity by forcing them to wait for build results before proceeding with their tasks. I have experienced pipelines that took up to 60 minutes to run, only to fail at the last step, requiring a complete rerun and further delays. These lengthy cycles can erode developer trust in the CI process, contribute to frustration, and ultimately slow down the entire software delivery cycle. Moreover, long-running tests can lead to resource contention, increased costs because of wasted computing power, and reduced overall efficiency of the development process.</p><p>With parallel test execution in CodeBuild, you can now run your tests concurrently across multiple build compute environments. This feature implements a sharding approach where each build node independently executes a subset of your test suite. CodeBuild provides environment variables that identify the current node number and the total number of nodes, which are used to determine which tests each node should run. There is no control build node or coordination between nodes at build time—each node operates independently to execute its assigned portion of your tests.</p><p>To enable test splitting, configure the <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/batch-build-buildspec.html#build-spec.batch.build-fanout">batch fanout</a> section in your <code>buildspec.xml</code>, specifying the desired parallelism level and other relevant parameters. Additionally, use the <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/parallel-test-tests-run.html">codebuild-tests-run</a> utility in your build step, along with the appropriate test commands and the chosen splitting method.</p><p>The tests are split based on the sharding strategy you specify. <code>codebuild-tests-run</code> offers two sharding strategies:</p><ul><li><strong>Equal-distribution.</strong> This strategy sorts test files alphabetically and distributes them in chunks equally across parallel test environments. Changes in the names or quantity of test files might reassign files across shards.</li><li><strong>Stability.</strong> This strategy fixes the distribution of tests across shards by using a consistent hashing algorithm. It maintains existing file-to-shard assignments when new files are added or removed.</li></ul><p>CodeBuild supports automatic merging of test reports when running tests in parallel. With automatic test report merging, CodeBuild consolidates tests reports into a single test summary, simplifying result analysis. The merged report includes aggregated pass/fail statuses, test durations, and failure details, reducing the need for manual report processing. You can view the merged results in the <a href="https://console.aws.amazon.com/codebuild">CodeBuild console</a>, retrieve them using the <a href="https://aws.amazon.com/cli/">AWS Command Line Interface (AWS CLI)</a>, or integrate them with other reporting tools to streamline test analysis.</p><p><strong>Let’s look at how it works</strong><br />Let me demonstrate how to implement parallel testing in a project. For this demo, I created <a href="https://github.com/sebsto/aws-codebuild-parallel-testing">a very basic Python project with hundreds of tests</a>. To speed things up, I asked <a href="https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line.html">Amazon Q Developer on the command line</a> to create a project and 1,800 test cases. Each test case is in a separate file and takes one second to complete. Running all tests in a sequence requires 30 minutes, excluding the time to provision the environment.</p><p>In this demo, I run the test suite on ten compute environments in parallel and measure how long it takes to run the suite.</p><p>To do so, I added a <code>buildspec.yml</code> file to my project.</p><pre class="lang-yaml">version: 0.2batch: fast-fail: false build-fanout: parallelism: 10 # ten runtime environments ignore-failure: falsephases: install: commands: - echo 'Installing Python dependencies' - dnf install -y python3 python3-pip - pip3 install --upgrade pip - pip3 install pytest build: commands: - echo 'Running Python Tests' - | codebuild-tests-run \ --test-command 'python -m pytest --junitxml=report/testreport.xml' \ --files-search "codebuild-glob-search 'tests/test.py'" \ --sharding-strategy 'equal-distribution' post_build: commands: - echo "Test execution completed"reports: pytest_reports: files: - ".xml" base-directory: "report" file-format: JUNITXML </pre><p>There are three parts to highlight in the YAML file.</p><p>First, there’s a <code>build-fanout</code> section under <code>batch</code>. The <code>parallelism</code> command tells CodeBuild how many test environments to run in parallel. The <code>ignore-failure</code> command indicates if failure in any of the fanout build tasks can be ignored.</p><p>Second, I use the pre-installed <code>codebuild-tests-run</code> command to run my tests.</p><p>This command receives the complete list of test files and decides which of the tests must be run on the current node.</p><ul><li>Use the <code>sharding-strategy</code> argument to choose between equally distributed or stable distribution, as I explained earlier.</li><li>Use the <code>files-search</code> argument to pass all the files that are candidates for a run. We recommend to use the provided <code>codebuild-glob-search</code> command for performance reasons, but any file search tool, such as <a href="https://man7.org/linux/man-pages/man1/find.1.html">find(1)</a>, will work.</li><li>I pass the actual test command to run on the shard with the <code>test-command</code> argument.</li></ul><p>Lastly, the <code>reports</code> section instructs CodeBuild to collect and merge the test reports on each node.</p><p>Then, I open the CodeBuild console to create a project and a batch build configuration for this project. There’s nothing new here, so I’ll spare you the details. <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/create-project.html">The documentation has all the details to get you started</a>. <strong>Parallel testing works on batch builds. Make sure <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/batch-build.html">to configure your project to run in batch</a></strong>.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_14-53-45.png"><img class="aligncenter size-full wp-image-94361" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_14-53-45.png" alt="CodeBuild : create a batch build" width="822" height="937" /></a></p><p>Now, I’m ready to trigger an execution of the test suite. I can commit new code on my GitHub repository or trigger the build in the console.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_18-17-19.png"><img class="aligncenter size-full wp-image-94360" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_18-17-19.png" alt="CodeBuild : trigger a new build" width="1547" height="295" /></a></p><p>After a few minutes, I see a status report of the different steps of the build; with a status for each test environment or shard.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/21/2025-03-21_11-23-04b-1.png"><img class="aligncenter wp-image-94494 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/21/2025-03-21_11-23-04b-1.png" alt="CodeBuild: status" width="1412" height="1209" /></a></p><p>When the test is complete, I select the <strong>Reports</strong> tab to access the merged test reports.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_16-05-06.png"><img class="aligncenter size-full wp-image-94363" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/18/2025-03-18_16-05-06.png" alt="CodeBuild: test reports" width="1558" height="759" /></a></p><p>The <strong>Reports</strong> section aggregates all test data from all shards and keeps the history for all builds. I select my most recent build in the <strong>Report history</strong> section to access the detailed report.</p><p><a href="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/21/2025-03-21_11-23-24.png"><img class="aligncenter wp-image-94495 size-full" src="https://d2908q01vomqb2.cloudfront.net/da4b9237bacccdf19c0760cab7aec4a8359010b0/2025/03/21/2025-03-21_11-23-24.png" alt="CodeBuild: Test Report" width="1422" height="1191" /></a></p><p>As expected, I can see the aggregated and the individual status for each of my 1,800 test cases. In this demo, they’re all passing, and the report is green.</p><p>The 1,800 tests of the demo project take one second each to complete. When I run this test suite sequentially, it took 35 minutes to complete. When I run the test suite in parallel on ten compute environments, it took 6 minutes to complete, including the time to provision the environments. <strong>The parallel run took 17.9 percent of the time of the sequential run</strong>. Actual numbers will vary with your projects.</p><p><strong>Additional things to know<br /></strong> This new capability is compatible with all testing frameworks. <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/sample-parallel-test.html">The documentation includes examples</a> for Django, Elixir, Go, Java (Maven), Javascript (Jest), Kotlin, PHPUnit, Pytest, Ruby (Cucumber), and Ruby (RSpec).</p><p>For test frameworks that don’t accept space-separated lists, <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/parallel-test-tests-run.html">the <code>codebuild-tests-run</code> CLI provides a flexible alternative</a> through the <code>CODEBUILD_CURRENT_SHARD_FILES</code> environment variable. This variable contains a newline-separated list of test file paths for the current build shard. You can use it to adapt to different test framework requirements and format test file names.</p><p>You can further customize how tests are split across environments by writing your own sharding script and using the <code>CODEBUILD_BATCH_BUILD_IDENTIFIER</code> environment variable, which is automatically set in each build. You can use this technique to implement framework-specific parallelization or optimization.</p><p><strong>Pricing and availability<br /></strong> With parallel test execution, you can now complete your test suites in a fraction of the time previously required, accelerating your development cycle and improving your team’s productivity.</p><p>Parallel test execution is available on all <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-compute-types.html">three compute modes offered by CodeBuild</a>: on-demand, reserved capacity, and <a href="https://aws.amazon.com/lambda/">AWS Lambda</a> compute.</p><p>This capability is available today in all <a href="https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html#region">AWS Regions</a> where CodeBuild is offered, with no additional cost beyond <a href="https://aws.amazon.com/codebuild/pricing/">the standard CodeBuild pricing</a> for the compute resources used.</p><p>I invite you to try parallel test execution in CodeBuild today. Visit the <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/parallel-test.html">AWS CodeBuild documentation</a> to learn more and get started with parallelizing your tests.</p><a href="https://linktr.ee/sebsto">— seb</a><p>PS: Here’s the prompt I used to create the demo application and its test suite: “I’m writing a blog post to announce codebuild parallel testing. Write a very simple python app that has hundreds of tests, each test in a separate test file. Each test takes one second to complete.”</p><hr /><p>How is the News Blog doing? Take this <a href="https://amazonmr.au1.qualtrics.com/jfe/form/SV_eyD5tC5xNGCdCmi">1 minute survey</a>!</p><p><em>(This <a href="https://amazonmr.au1.qualtrics.com/jfe/form/SV_eyD5tC5xNGCdCmi">survey</a> is hosted by an external company. AWS handles your information as described in the <a href="https://aws.amazon.com/privacy/">AWS Privacy Notice</a>. AWS will own the data gathered via this survey and will not share the information collected with survey respondents.)</em></p></section><aside id="Comments" class="blog-comments"><div data-lb-comp="aws-blog:cosmic-comments" data-env="prod" data-content-id="cf48437c-d36f-473d-9c11-ffc88cd9b664" data-title="Accelerating CI with AWS CodeBuild: Parallel test execution now available" data-url="https://aws.amazon.com/blogs/aws/accelerating-ci-with-aws-codebuild-parallel-test-execution-now-available/"><p data-failed-message="Comments cannot be loaded… Please refresh and try again.">Loading comments…</p></div></aside>