# Job Coverage

Sun* CI can collect the test coverage information of your favorite testing tool and visualize this information. Collecting the coverage information is done via Sun* CI's coverage feature. You can specify one coverage report each job to collect.

For the coverage analysis to work, you have to provide a properly formatted Cobertura XML or Clover XML.

# Coverage change

New feature is coverage change is used to calculate the changes of code coverage, current Sun * CI will compare recent build with new build when they are in the same target branch. Attention, SUN* CI only compare builds as complete.

In case it's always right:

  • New pull request push to branch, SUN* CI will compare coverage of new pull request with coverage of branch
  • Branch A push to Branch B, SUN* CI will compare coverage of branch B with coverage of branch A

Example

  1. User A create pull request and push to brand Main.

create_pull_request.png

  1. SUN* CI will get coverage of main and compare coverage of new pull request (new_pull_request)

checkpull.png

  1. SUN * CI will report coverage percentage change, you can see the properties of the code coverage through the test results on the test result page

result.png

# Example test coverage configurations

# PHP example

The following .sun-ci.yml example use PHPUnit for testing and generate Clover XML result file.

jobs:
- name: test:phpunit
  stage: test
  image: sunasteriskrnd/php-workspace:7.4
  workspace: shared
  script:
  - phpunit --coverage-clover ./coverage.xml --coverage-html=coverage
  coverage:
    type: clover
    path: coverage.xml
  artifacts:
    paths:
    - coverage
    expires_in: 3 days

# Ruby example

Install gem simplecov-cobertura:

$ gem install simplecov-cobertura

Usage: At file spec/spec_helper.rb, add this


require 'simplecov-cobertura'

SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter

Config .sun-ci.yml:

jobs:
- name: test:rspec
  stage: test
  image: sunci/ruby:2.5.1
  before_script:
  - bundle _2.1.4_ install --path vendor/bundle
  - bundle exec rake db:structure:load db:migrate
  script:
  - bundle _2.1.4_ exec rspec --format progress --format html --out ./.sun-ci-reports/rspec.html spec
  coverage:
    type: cobertura
    path: ./.sun-ci-reports/coverage/coverage.xml
  artifacts:
    paths:
    - ./.sun-ci-reports/coverage/
    - ./.sun-ci-reports/rspec.html
    expires_in: 3 days