RSpec testing parallel jobs with CircleCI and JUnit XML report
You will learn how to run RSpec tests for your Ruby on Rails project on CircleCI with parallel jobs to shorten the running time of your CI build. Moreover, you will learn how to configure JUnit formatter to generate an XML report for your tests to show failing RSpec test examples nicely in CircleCI web UI. Finally, you will see how to automatically detect slow spec files and divide their test examples between parallel jobs to eliminate the bottleneck job that’s taking too much time to run tests.
Ruby gems to configure your RoR project
Here are the key elements you need:
- rspec_junit_formatter - it’s a ruby gem that generates an XML report for executed tests with information about test failures. This report can be automatically read by CircleCI to present it in CircleCI web UI. No more browsing through long RSpec output - just look at highlighted failing specs in the
TESTS
tab :)
- knapsack_pro - it’s a Ruby gem for running tests on parallel CI jobs to ensure all jobs finish work at a similar time to save you as much time as possible and eliminate bottlenecks.
- It uses the Queue Mode to dynamically split test files between parallel jobs.
- Knapsack Pro can also detect your slow RSpec test files and divide them between parallel jobs by test examples. You don’t have to manually split your big spec file into smaller files if you want to split work between parallel container on CircleCI :)
Just add the above gems to your Gemfile
.
For Knapsack Pro you will need an API token and you need to follow the installation guide to configure your project.
If you use knapsack_pro
gem in Queue Mode with CircleCI you may want to collect metadata like JUnit XML report about your RSpec test suite.
It’s important to copy the XML report to /tmp/test-results
. Learn more about collecting metadata on CircleCI in the docs.
CircleCI YML configuration for RSpec
Here is the complete CircleCI YML config file for RSpec, Knapsack Pro and JUnit formatter.
Summary
You’ve just learned how to make your CircleCI builds way faster! Now your RSpec tests can be automatically run on many parallel machines to save you time. Please let us know if it was helpful or if you have any questions. Feel free to sign up at Knapsack Pro or down below and try it yourself.