How to setup Code Climate Quality test coverage with Bitrise
Quality by Code Climate is a web service that gives you analytics for your code. It analyzes your code for code smells, and with proper CI/CD integration, it can track changes in test coverage data.
This article will list, step by step, how to set up Code Climate test coverage upload from Bitrise - probably most famous and widely used mobile Continues Integration and Continues Delivery service.
Initial assumption: Your GitHub repository is added to the Quality by Code Climate and the Bitrise.
-
Get Code Climate’s test reporters ID - visit
Repo Settingson Code Climate and openTest coverage. -
Add ID from the previous step as a Bitrise Secret with a name
CC_TEST_REPORTER_ID(if you want to test Pull Requests activeExpose for Pull Requests?) -
Generate GitHub personal access token (only
public_repopermission is needed) -
Add token from the previous step as a Bitrise Secret with a name
GITHUB_ACCESS_TOKEN(if you want to test Pull Requests activeExpose for Pull Requests?)
-
Turn on gathering test coverage in your Xcode project.
Edit Scheme...->Testphase and select checkbox onGather coverage for...inCode Coveragesection.
-
In Bitrise, go to your Tests workflow, and before
Xcode Test for iOSstep, add a new Script phase with content visible below. It will download Code Climate test runner (cc-test-reporter) and updates Code Climate that test coverage is being prepared.
#!/usr/bin/env bash
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- Add a new step after
Xcode Test for iOSand paste provided content. This script usesxcrun xccovto formatTests.xcresultfile to JSON and uploads it using the previously downloadedcc-test-reporterscript.
#!/usr/bin/env bash
xcrun xccov view --report $BITRISE_XCRESULT_PATH --json > coverage.json
./cc-test-reporter after-build --coverage-input-type xccov
- In Xcode Test for iOS step set
Generate code coverage files? tono. Note: I’m not sure why, but I had a problem finishing that step with this set toyes.
That’s it. With that few simple steps, you can send test coverage data from Bitrise to Code Climate.