Skip to content

Codecov: Getting Started

Yarden Lev edited this page Apr 4, 2017 · 1 revision

This page is based on SmartCity-Market's wiki page regarding Codecov, with some modifications.

About Codecov

Codecov allows us to:

  • Measure the code coverage of our project
  • Have a nice Dashboard that provides detailed statistics
  • Ignore folders and / or files we do not want to include while computing the code coverage of our project.

Note: You can use Codecov in all of your public repositories and one private repository, for free.

Integration

This steps describes how to start working with Codecov in a Maven Java project:

  1. Sign in Codecov with your GitHub account.
  2. Select the repository you want to apply Codecov for. (Projects under TechnionYP5777 were already granted access)
  3. Add the following to your pom.xml file:
<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>cobertura-maven-plugin</artifactId>
	<version>2.7</version>
	<configuration>
		<formats>
			<format>html</format>
			<format>xml</format>
		</formats>
		<check />
	</configuration>
</plugin>
  1. Add the following to your .travis.yml file:
# safe list: add here branches you want to verify the build & tests will pass
branches:
 only:
  - master


# add this if you use maven for your project and want to verify mvn build is successful and all unit tests pass.
script:
 - mvn test
 - mvn cobertura:cobertura


# running coverage tool
after_success:
- bash <(curl -s https://codecov.io/bash)
  1. Add a codecov.yml file.
  • This file contains configurations of the Codecov's coverage process.
  • It has many optional sections, we will focus on the ignore section.
  • The ignore section allows us to exclude files from the code coverage computations.
    • Its location is under the coverage section.
    • It is excellent for excluding GUI files that usually are not tested using unit tests and thus decreasing overall coverage.
    • In order to exclude a file, add its path under the ignore section, surrounded by quotations marks. For example: "src/main/java/il/ac/technion/cs/smarthouse/applications/PremadeApplications.java"
    • In order to exclude a whole folder, add its path with a /* at the end under the ignore section, surrounded by quotations marks. For example: "src/main/java/il/ac/technion/cs/smarthouse/applications/*"
  1. Commit and push your changes. Travis checks should pass and you should be able to see your project's code coverage and statistics in your project's Dashboard.

Bonus

You can add badges to your project's README.md file.

  • Badges provides information about your project and being updated dynamically (you can click them for more details).
  • You can see our badges in our README file (your project's badges will be similar).
    • For coverage badge we added:
    [![codecov](https://codecov.io/gh/TechnionYP5777/Smartcity-Smarthouse/branch/master/graph/badge.svg)](https://codecov.io/gh/TechnionYP5777/Smartcity-Smarthouse)
    
    • For build badge we added:
    [![Build Status](https://travis-ci.org/TechnionYP5777/Smartcity-Smarthouse.svg?branch=master)](https://travis-ci.org/TechnionYP5777/Smartcity-Smarthouse)
    

Clone this wiki locally