Skip to content

Integrating Codecov with a GitHub project (Coverage tool)

Idan Atias edited this page Jan 9, 2017 · 7 revisions

What is Codecov?

Codecov is a tool for measuring the degree to which the source code of a program is executed when a particular test suite runs.

Why do we need it?

Testing source code helps prevents bugs and syntax errors by executing each line with a known variable and asserting an expected output. This tool lets us know how much of our code is tested and therefor helps developers reduce chances for bugs and other errors.

Pricing

Free for public repositories :)

How do we integrate it with GitHub?

  1. Sign up in codecov.io via your GitHub account

  2. Choose the repository you want to apply the coverage for. (Projects under TechnionYPP were already granted access)

  3. Update your pom.xml, as seen here

  4. Update your .travis.yml, as seen here (make sure to have "mvn cobertura:cobertura" line in your travis file [under "script"])

  5. Creating the codecov.yml file - This file (like .travis.yml file) holds the configuration for the coverage operation. Here is our (SmartMarket) codecov. It pretty much explains itself but there are few things that will be better to know: ignore: state there all files which are not "meant" to be unit-tested, like GUI and constants-files so coverage percent won't be reduce by this code. range: below minimum range, coverage badge (we'll get to badges in a sec) will be red, and as approching to 100% it will become greener.

  6. Commit changes to pom.xml, travis.yml & codecov.yml and push it to master. TravisCI will now automatically run the coverage for your project. You can see it Travis logs (for example: https://travis-ci.org/TechnionYP5777/SmartCity-Market/builds/190092251)

  7. If you did all correctly, Travis should succeed in building the project & running the coverage. The coverage result can be found under your repository section in codecov.io. For example - this is the SmartMarket codecov page. You can search this site for more cool analyses you can do to your code.

  8. Add badges to your project's README file: A badge is like a "live" icon that lets the developers (and the visitors) of a repository know the status of their project. For example - if the build is passing or not and what is the coverage percent. For getting the coverage badge add "[![codecov](https://codecov.io/gh/TechnionYP5777/project-name/branch/master/graph/badge.svg)](https://codecov.io/gh/TechnionYP5777/project-name)". For adding a "build" badge add "[![Build Status](https://travis-ci.org/TechnionYP5777/project-name.png)](https://travis-ci.org/TechnionYP5777/project-name)"

After last stage is done, you should have something similar to these badges:

Build Status

codecov

Pressing on them will lead you to Travis/Codecov websites for more details.

(You can also install the Codecov chrome extension from here for "seeing" the coverage on the files in github)

That's it! :)