Generating Code Coverage

Note: This guide details how to generate code coverage when using Scrutinizer as your CI service. Please refer to sending external code coverage if you are using Scrutinizer for automated code reviews only.

Scrutinizer can process code coverage information that you generate during your build. We currently support code coverage processing for PHP, Python and Ruby, and also support merging your code coverage data should you run tests in parallel.

PHP

For PHP, we support the clover format that is generated for example by phpunit. When setting up your test commands, simply specify where we find the coverage file and what format it has:

build:
    tests:
        override:
            -
                command: 'phpunit --coverage-clover=some-file'
                coverage:
                    file: 'some-file'
                    format: 'clover'

Python

For Python, we support data generated by coverage. When setting up your test commands, simply specify where we find the .coverage file, and potentially your .coveragerc configuration file:

build:
    tests:
        override:
            -
                command: './run-tests.sh'
                coverage:
                    file: '.coverage'
                    config_file: '.coveragerc'
                    format: 'py-cc'

Ruby

For Ruby, code coverage can be generated using our scrutinizer-ocular gem that uses SimpleCov internally. When you have set-up the scrutinizer-ocular gem, make sure to set the SCRUTINIZER_CC_FILE environment variable:

build:
    tests:
        override:
            -
                command: 'bundle exec rspec spec'
                environment:
                    'SCRUTINIZER_CC_FILE': 'my-coverage'
                coverage:
                    file: 'my-coverage'
                    format: 'rb-cc'

Javascript

We also support the clover format for Javascript. Coverage can be generated by tools like istanbul.

Popular test runners like karma can use istanbul by way of plugins such as karma-coverage.

build:
    dependencies:
        before:
            - npm install istanbul   # or add it as part of your package.json

    tests:
        override:
            -
                command: 'istanbul cover --report clover test.js'
                coverage:
                    file: 'coverage/clover.xml'
                    format: 'clover'