From c40e1703dcd96d41ba99943080514186c8cf6aac Mon Sep 17 00:00:00 2001 From: Binnette Date: Thu, 21 Nov 2024 22:38:35 +0100 Subject: [PATCH] Jacoco and Coveralls --- .github/workflows/android.yml | 9 +++++++-- README.md | 3 ++- app/build.gradle | 28 ++++++++++++++++++++++++++++ build.gradle | 4 ++++ 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 4bf46b48..18146adc 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -31,5 +31,10 @@ jobs: - name: Build with Gradle run: ./gradlew build --stacktrace - - name: Run unit tests - run: ./gradlew testDebugUnitTest --stacktrace + - name: Run unit tests and jacoco coverage + run: ./gradlew testDebugUnitTest jacocoTestReport --stacktrace + + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@v2.3.4 + with: + format: jacoco diff --git a/README.md b/README.md index 0403e78f..1538a222 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # OSMTracker for Androidâ„¢ -![Build](https://github.com/labexp/osmtracker-android/actions/workflows/android.yml/badge.svg) +![Build](https://github.com/labexp/osmtracker-android/actions/workflows/android.yml/badge.svg?branch=develop) +[![Coverage Status](https://coveralls.io/repos/github/labexp/osmtracker-android/badge.svg?branch=develop)](https://coveralls.io/github/labexp/osmtracker-android?branch=develop) **OSMTracker for Androidâ„¢** is a mobile app designed for OpenStreetMap mappers and outdoor adventurers. It lets you log a GPS track to document your journey. Its customizable buttons let you simply add POIs as track points directly inside your GPX track. diff --git a/app/build.gradle b/app/build.gradle index b1a144e1..a52e8b2e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'jacoco' android { @@ -134,3 +135,30 @@ repositories { mavenCentral() maven { url "https://jitpack.io" } } + +jacoco { + toolVersion = "0.8.12" +} + +tasks.withType(Test) { + jacoco.includeNoLocationClasses = true + jacoco.excludes = ['jdk.internal.*'] +} + +tasks.register("jacocoTestReport", JacocoReport) { + dependsOn testDebugUnitTest + + reports { + xml.required = true + } + + def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*'] + def mainSrc = "${project.projectDir}/src/main/java" + + sourceDirectories.setFrom(files([mainSrc])) + classDirectories.setFrom(fileTree(dir: layout.buildDirectory.dir("intermediates/javac/debug").get().asFile, excludes: fileFilter)) + executionData.setFrom(fileTree(dir: layout.buildDirectory.get(), includes: [ + 'jacoco/testDebugUnitTest.exec', 'outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec' + ])) + +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 138c9546..f23961bd 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,10 @@ buildscript { } } +plugins { + id 'jacoco' +} + allprojects { repositories { google()