BadgeYaY already has Travis CI and Codacy to test code quality and Pull Request but there was no support for testing Code Coverage in repository against every Pull Request. So I decided to go with setting up Codecov to test the code coverage.
Let’s get started and understand it step by step.
What is Code Coverage ?
Code coverage is a measurement used to express which lines of code were executed by a test suite. We use three primary terms to describe each lines executed.
- hit indicates that the source code was executed by the test suite.
- partial indicates that the source code was not fully executed by the test suite; there are remaining branches that were not executed.
- miss indicates that the source code was not executed by the test suite.
Coverage is the ratio of hits / (hit + partial + miss). A code base that has 5 lines executed by tests out of 12 total lines will receive a coverage ratio of 41% . In BadgeYaY , Code Coverage is 100%.
How CodeCov helps in Code Coverage ?
Codecov focuses on integration and promoting healthy pull requests. Codecov delivers <<<or “injects”>>> coverage metrics directly into the modern workflow to promote more code coverage, especially in pull requests where new features and bug fixes commonly occur.
I am listing down top 5 Codecov Features:
- Browser Extension
- Pull Request Comments
- Commit Status
- Merging Reports
- Flags e.g. #unittests vs #functional
We can change the configuration of how Codecov processes reports and expresses coverage information. Let’s see how we configure it according to BadgeYaY by integrating it with Travis CI.
Now generally, the codecov works better with Travis CI. With the one line
the code coverage can now be easily reported.
Add a script for testing:
Here is a particular example of travis.yml from the project repository of BadgeYaY:
Let’s have a look at Codecov.yml to check exact configuration that I have used for BadgeYaY.
Now when anyone makes a Pull Request to BadgeYaY, Codecov will analyze the Pull Request according to above configuration and generate a Report showing the code coverage of that Pull Request.
Below is the screenshot of all test passing in BadgeYaY repository
This is how we setup codecov in BadgeYaY repository. And like this way, it can be set up in other repositories as well.
The related PR of this work is https://github.com/fossasia/badgeyay/pull/400
- CodeCov Documentation – Link