Fail fast testing
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
Fail fast testing runs the test specs most relevant to your merge request changes before the rest of the suite runs. If those specs fail, the pipeline stops immediately to save time and compute resources.
For Ruby on Rails projects that use RSpec, the
Verify/FailFast CI/CD template
selects and runs only the relevant specs. It uses the
test_file_finder (tff) gem,
which maps changed files to their related spec files.
By default, the template runs in the .pre stage,
before all other pipeline stages.
Configure fail fast testing
Configure fail fast testing to get faster feedback on merge request changes before your full test suite runs.
Prerequisites:
- A Ruby on Rails project that uses RSpec.
- Merged results pipelines enabled in the project settings. This also requires merge request pipelines to be enabled.
To configure fail fast testing:
-
Add an RSpec job to run your full suite on merge request pipelines:
rspec-complete: stage: test rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" script: - bundle install - bundle exec rspec -
Include the
Verify/FailFasttemplate in your CI/CD configuration:include: - template: Verify/FailFast.gitlab-ci.yml -
Optional. To use a different Docker image, set the image on the
rspec-rails-modified-path-specsjob in your CI/CD configuration file:include: - template: Verify/FailFast.gitlab-ci.yml rspec-rails-modified-path-specs: image: custom-docker-image-with-ruby
Fail fast test results
The following examples assume a suite of 100 specs per model across 10 models (1000 specs total).
| Changed files | rspec-rails-modified-path-specs |
rspec-complete |
|---|---|---|
| No Ruby files | Does not run | Runs all 1000 specs |
app/models/example.rb (all specs pass) |
Runs 100 specs for example.rb |
Runs all 1000 specs |
app/models/example.rb (any spec fails) |
Runs 100 specs for example.rb |
Skipped |