Code Climate Code quality, coverage measurement

The effect has not been measured yet, and we will evaluate it as we use it.

Overview

Use Code Climate to automatically check code quality and test coverage coverage.

Code Climate

Quality

https://codeclimate.com/quality/

CI. Measure code quality in units of repositories and files. You can also measure test coverage if you set it up. The code quality check seems to be powerful, and it seems to evaluate in detail such as code duplication. This time there is too little code in the repository (just Hello World.) And it hasn't been evaluated yet, so I'm still not sure how effective it is. Detailed article

Velocity

https://codeclimate.com/velocity/

Ability to measure team productivity. Still BETA version.

URL

https://codeclimate.com

Corresponding service

It also supports Webhooks, and you can set a forced check before merging.

price

$ 20 a month. Public repositories are free.

Linkage with Git repository

Very easy. Login linkage (OAuth) of the supported service and select the target repository from the list.

Code Climate Quality

MAINTAINABILITY

Measure code quality. Even if nothing is set, the analysis is done without permission when the repositories are linked.

TEST COVERAGE

Measure test coverage. It doesn't work when the repositories are linked, but it works when set.

Setting

Forced check before merging GitHub

  1. Open Repo Setting

  2. Open GitHub

  3. Open Pull request status

  4. The authentication screen will appear. Select the target repository and add it.

  5. In the GitHub repository, set Code Climate to require in the Setting Branch settings.

  6. Added coverage file transmission process to CI tool configuration file --Specifications and usage are described at https://docs.codeclimate.com/docs/configuring-test-coverage

  7. Wercker was not in the sample, so the method is described below, and coverage measurement uses Jacoco.

  8. Add CC_TEST_REPORTER_ID = Token issued by Code Climate to Wercker environment variables

  9. Add the following to the step before build

    ```
    # cc-test-reporter use env CC_TEST_REPORTER_ID
    - script:
        name: post coverage to code climate before
        code: |
          curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          chmod +x ./cc-test-reporter
          ./cc-test-reporter before-build
    ```
    
  10. Add the following to the step after build

    ```
    - script:
        name: post coverage to code climate after
        code: |
          export JACOCO_SOURCE_PATH="src/main/java"
          ./cc-test-reporter format-coverage build/reports/jacoco/test/jacocoTestReport.xml --input-type jacoco
          ./cc-test-reporter upload-coverage
    ```
    

The whole picture of wercker.yml

# This references an OpenJDK container from the
# Docker Hub https://hub.docker.com/_/openjdk/
# Read more about containers on our dev center
# http://devcenter.wercker.com/docs/containers/index.html
box: openjdk:10.0.1-jdk

# defining the dev pipeline
dev:
  steps:
    # A step that executes `gradle bootRun` command
    - script:
      name: run gradle
      code: |
        ./gradlew bootRun

# Build definition
build:
  # The steps that will be executed on build
  steps:
    # A step that executes `gradle build` command
    # cc-test-reporter use env CC_TEST_REPORTER_ID
    - script:
        name: post coverage to code climate before
        code: |
          curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          chmod +x ./cc-test-reporter
          ./cc-test-reporter before-build
    - script:
        name: run gradle
        code: |
          ./gradlew --full-stacktrace -q --project-cache-dir=$WERCKER_CACHE_DIR build
    - script:
        name: post coverage to codecov
        code: |
          bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN
    - script:
        name: post coverage to code climate after
        code: |
          export JACOCO_SOURCE_PATH="src/main/java"
          ./cc-test-reporter format-coverage build/reports/jacoco/test/jacocoTestReport.xml --input-type jacoco
          ./cc-test-reporter upload-coverage

badge

You can get code quality and test coverage badge display links from Repo Setting. Describe it in README.md and display it at the top of the repository.

Recommended Posts

Code Climate Code quality, coverage measurement
Java coverage measurement library
About types of code coverage
Get JUnit code coverage on Android.