Back to Gitlabhq

Fail fast testing

doc/ci/testing/fail_fast_testing.md

19.0.02.6 KB
Original Source

{{< details >}}

  • Tier: Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

{{< /details >}}

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:

To configure fail fast testing:

  1. Add an RSpec job to run your full suite on merge request pipelines:

    yaml
    rspec-complete:
      stage: test
      rules:
        - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      script:
        - bundle install
        - bundle exec rspec
    
  2. Include the Verify/FailFast template in your CI/CD configuration:

    yaml
    include:
      - template: Verify/FailFast.gitlab-ci.yml
    
  3. Optional. To use a different Docker image, set the image on the rspec-rails-modified-path-specs job in your CI/CD configuration file:

    yaml
    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 filesrspec-rails-modified-path-specsrspec-complete
No Ruby filesDoes not runRuns all 1000 specs
app/models/example.rb (all specs pass)Runs 100 specs for example.rbRuns all 1000 specs
app/models/example.rb (any spec fails)Runs 100 specs for example.rbSkipped