Github 集成 Codecov 做测试覆盖率

首先贴一下官网的快速开始

Getting Started

Basic Usage

  1. Sign up on codecov.io and link either your GitHub, GitLab, or Bitbucket account.

  2. Once linked, Codecov will automatically sync all the repositories to which you have access.

  3. You can click on an organization from your dashboard to access its repositories, or navigate directly to a specific repository using: https://codecov.io///. Example: https://codecov.io/gh/scrapy/scrapy.
    A repository that has no coverage reports uploaded to codecov. Note that the repository upload token is displayed here.
    A repository that has no coverage reports uploaded to codecov. Note that the repository upload token is displayed here.
    Github 集成 Codecov 做测试覆盖率_第1张图片

  4. Use the bash uploader and a repository upload token, to upload a coverage report to Codecov.

  5. Navigate back to the repository on Codecov, and you should see coverage information.

可以看见原理很简单,主动把测试覆盖率的报告通过Codecov提供的脚本(bash uploader)上传就行了(bash <(curl -s https://codecov.io/bash)),如果是私有仓库,则上传的时候需要添加上图中的token。

下面说说Travis + Codecov + Maven

这里需要利用到一个覆盖率的包jacoco:

  1. pom.xml添加jacoco的maven插件:
<plugin>
    <groupId>org.jacocogroupId>
    <artifactId>jacoco-maven-pluginartifactId>
    <version>0.7.9version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agentgoal>
            goals>
        execution>
        <execution>
            <id>reportid>
            <phase>testphase>
            <goals>
                <goal>reportgoal>
            goals>
        execution>
    executions>
plugin>
  1. .travis.yml增加codecov的上传配置:
language: java
after_success:
  - bash <(curl -s https://codecov.io/bash)
  1. 提交代码

你可能感兴趣的:(Java)