summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlangsmith <langstonlmcs@gmail.com>2019-03-07 17:08:48 -0800
committerlangsmith <langstonlmcs@gmail.com>2019-03-12 18:21:47 -0700
commit975936f370cb17811e388105c9066c8a2c7ad6a0 (patch)
treef9d7fa7edd5e28abb897efefb51d2720f6dcb7dd
parent565792606d5d03d0cc9889f112bb50345c899005 (diff)
downloadqtlocation-mapboxgl-upstream/ls-adding-android-code-cov.tar.gz
[android] initial android code coverage additionsupstream/ls-adding-android-code-cov
-rw-r--r--Makefile10
-rw-r--r--circle.yml10
-rw-r--r--platform/android/MapboxGLAndroidSDK/build.gradle3
-rw-r--r--platform/android/build.gradle1
-rw-r--r--platform/android/gradle/dependencies.gradle2
-rwxr-xr-xplatform/android/scripts/android-code-coverage.sh49
6 files changed, 75 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index ecc4273cff..914289c56f 100644
--- a/Makefile
+++ b/Makefile
@@ -731,6 +731,16 @@ android-check : android-checkstyle android-lint-sdk android-lint-test-app
android-checkstyle: platform/android/gradle/configuration.gradle
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=none :MapboxGLAndroidSDK:checkstyle :MapboxGLAndroidSDKTestApp:checkstyle
+# Runs unit test code coverage on the Android code
+.PHONY: android-unit-test-code-coverage
+android-unit-test-code-coverage: platform/android/gradle/configuration.gradle
+ cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=all clean :MapboxGLAndroidSDK:jacocoTestReportDebug
+
+# Runs unit test code coverage on the Android code
+.PHONY: android-code-coverage-report-to-text-file
+android-code-coverage-report-to-text-file: platform/android/gradle/configuration.gradle
+ textutil -convert txt platform/android/MapboxGLAndroidSDK/build/reports/jacoco/debug/index.html
+
# Runs lint on the Android SDK code
.PHONY: android-lint-sdk
android-lint-sdk: platform/android/gradle/configuration.gradle
diff --git a/circle.yml b/circle.yml
index 4a54e06931..c051ef0b23 100644
--- a/circle.yml
+++ b/circle.yml
@@ -643,6 +643,12 @@ jobs:
- run:
name: Build release Test App
command: make android
+ - run:
+ name: Build unit test code coverage reports for MapboxGLAndroidSDK module
+ command: make android-unit-test-code-coverage
+ - run:
+ name: Convert code coverage report to raw text file
+ command: make android-code-coverage-report-to-text-file
- save-dependencies: { gradle: true }
- run:
name: gzip debugable .so files
@@ -665,6 +671,10 @@ jobs:
- run:
name: Record size
command: platform/android/scripts/metrics.sh
+ - run:
+ name: Report Android code coverage
+ command: |
+ platform/android/scripts/android-code-coverage.sh CI
- deploy:
name: Publish to Bintray
command: |
diff --git a/platform/android/MapboxGLAndroidSDK/build.gradle b/platform/android/MapboxGLAndroidSDK/build.gradle
index 257da91b6b..31652badda 100644
--- a/platform/android/MapboxGLAndroidSDK/build.gradle
+++ b/platform/android/MapboxGLAndroidSDK/build.gradle
@@ -1,6 +1,8 @@
apply plugin: 'com.android.library'
apply plugin: "com.jaredsburrows.license"
apply plugin: 'kotlin-android'
+apply plugin: "com.vanniktech.android.junit.jacoco"
+
dependencies {
lintChecks project(":MapboxGLAndroidSDKLint")
@@ -141,6 +143,7 @@ android {
buildTypes {
debug {
jniDebuggable true
+ testCoverageEnabled true
}
}
}
diff --git a/platform/android/build.gradle b/platform/android/build.gradle
index 5334c93ce9..97f3037afb 100644
--- a/platform/android/build.gradle
+++ b/platform/android/build.gradle
@@ -12,6 +12,7 @@ buildscript {
classpath dependenciesList.bintrayPlugin
classpath dependenciesList.artifactoryPlugin
classpath dependenciesList.androidPublishPlugin
+ classpath dependenciesList.jacocoPlugin
}
}
diff --git a/platform/android/gradle/dependencies.gradle b/platform/android/gradle/dependencies.gradle
index 600901ca76..335f90ad7b 100644
--- a/platform/android/gradle/dependencies.gradle
+++ b/platform/android/gradle/dependencies.gradle
@@ -27,6 +27,7 @@ ext {
bintray : '1.8.4',
artifactory : '4.9.3',
androidPublish : '3.6.2',
+ jacoco : '0.13.0',
lint : '26.1.4',
gms : '16.0.0',
reLinker : '1.3.1'
@@ -72,6 +73,7 @@ ext {
bintrayPlugin : "com.jfrog.bintray.gradle:gradle-bintray-plugin:${versions.bintray}",
artifactoryPlugin : "org.jfrog.buildinfo:build-info-extractor-gradle:${versions.artifactory}",
androidPublishPlugin : "digital.wup:android-maven-publish:${versions.androidPublish}",
+ jacocoPlugin : "com.vanniktech:gradle-android-junit-jacoco-plugin:${versions.jacoco}",
lint : "com.android.tools.lint:lint:${versions.lint}",
lintApi : "com.android.tools.lint:lint-api:${versions.lint}",
diff --git a/platform/android/scripts/android-code-coverage.sh b/platform/android/scripts/android-code-coverage.sh
new file mode 100755
index 0000000000..e2a2603fe1
--- /dev/null
+++ b/platform/android/scripts/android-code-coverage.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+set -e
+set -o pipefail
+
+#
+# Get the .txt file generated from the code coverage HTML report
+#
+cov_result="";
+if [ -d platform/android/MapboxGLAndroidSDK/build/reports/jacoco/ ]; then
+ cov_result=platform/android/MapboxGLAndroidSDK/build/reports/jacoco/debug/index.txt
+ echo "$cov_result"
+ echo "The value of \"cov_result\" is $cov_result."
+
+else
+ echo "Coverage file does not exist. Please run tests before executing"
+ exit 1
+fi
+
+# Retreive the total number of lines in the text file that was created via the coverage report's HTML file
+totalNumberOfLinesInDocument=$(wc -l < platform/android/MapboxGLAndroidSDK/build/reports/jacoco/debug/index.txt)
+echo "The value of \"totalNumberOfLinesInDocument\" is $totalNumberOfLinesInDocument."
+
+# The sixth line from the last line in the text file, is the number of lines missed. The fifth from the bottom is
+# is the total number which exist in the Maps SDK. So to we need to get these numbers, devide the 6th by the 5th,
+# and then multiple the product by 100 to get the coverage percentage.
+
+missed_lines_num=$(sed -n "$(($totalNumberOfLinesInDocument-6)),$(($totalNumberOfLinesInDocument-6))p;$(($totalNumberOfLinesInDocument-6))q" platform/android/MapboxGLAndroidSDK/build/reports/jacoco/debug/index.txt)
+echo "The value of \"missed_lines_num\" is $missed_lines_num."
+
+
+total_lines_num=$(sed -n "$(($totalNumberOfLinesInDocument-5)),$(($totalNumberOfLinesInDocument-5))p;$(($totalNumberOfLinesInDocument-5))q" platform/android/MapboxGLAndroidSDK/build/reports/jacoco/debug/index.txt)
+echo "The value of \"total_lines_num\" is $total_lines_num."
+
+# Convert the line coverage for the dynamic target to a percentage. Currently,
+# only CI tests are included when calculated code coverage.
+#
+# percentage= $"(($missed_lines / $total_lines))" | bc
+percentage=$(echo (($missed_lines_num / $total_lines_num)) | bc)
+
+echo "The code coverage percentage is $percentage."
+
+
+# NEED TO MULTIPLY $percentage BY 100
+
+
+# Pass info on to generic code-coverage.sh file
+
+# ./././scripts/code-coverage.sh $percentage "Android" "$1" \ No newline at end of file