Test coverage reports with Codecov

4 Aug 2022

Hello! Today I would like to demonstrate Codecov service usage and also Github Actions integration. Codecov helps to monitor project tests coverage.

Tests coverage calculation

Tests coverage calculation is provided with special tools depends on project stack. For PHP project it might be xdebug, pcov or phpdbg.

As a result there is coverage report file in xml format, or visual report in html format. Test coverage calculation for PHP project is described in another post.

Test coverage report in html format is available for review on local environment. For CI/CD it's can be uploaded to external server. There is an example: https://antonshell.me/post/php-code-coverage.

This process requires some configuration. There is external serer configuration required as well. Codecov helps to visualize coverage report in xml format. And also it's easy to configure.

Codecov configuration + Github Actions

1 . Create an account with github, gitlab или bitbucket: https://about.codecov.io/sign-up/.

2 . Generate CODECOV_TOKEN, then add in github secrets.

3 . Add codecov step to tests workflow. Example:

- name: Upload report to codecov
  uses: codecov/codecov-action@v2
  with:
    token: ${{ secrets.CODECOV_TOKEN }}
    files: ./coverage.xml
    flags: tests
    name: codecov-placeholder-service
    fail_ci_if_error: true
    verbose: true

4 . Attach codecov application to Github

There is a pull request for codecov configuration: https://github.com/antonshell/placeholder-service/pull/12

Codecov docs: https://docs.codecov.com/docs.

That's all for now. Thank you for your attention!