DEV Community

Cover image for See untested code in GitLab MRs
Augusts Bautra
Augusts Bautra

Posted on

2

See untested code in GitLab MRs

Today I got a nifty little GitLab feature configured for our Rails project - displaying which lines are lacking spec coverage in MR diff view.
The setup is simple, and I highly recommend you do this also. Works even on the free, self-hosted version!

Here's the official docs, I went down the Cobertura route.

Starting assumptions - you have Simplecov configured and already collecting coverage data in CI runs.

Steps remaining to do:

  1. Add the cobertura formatter
 gem "simplecov-cobertura", require: false
Enter fullscreen mode Exit fullscreen mode
  1. Set up multi-format formatting for Simplecov
  formatters = [
    # The default, human-readable HTML formatter for a coverage report
    SimpleCov::Formatter::HTMLFormatter,   
    # Cobertura XML formatter, for GitLab MRs
    defined?(SimpleCov::Formatter::CoberturaFormatter) ? SimpleCov::Formatter::CoberturaFormatter : nil
  ].compact

  SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters)
Enter fullscreen mode Exit fullscreen mode
  1. Add this configuration to GitLab CI yaml file (adjust the path)
  artifacts:
    reports:     
      coverage_report:
        coverage_format: cobertura
        path: path/to/coverage.xml
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay