diff --git a/.github/workflows/android.yml b/.github/workflows/build.yml similarity index 94% rename from .github/workflows/android.yml rename to .github/workflows/build.yml index 82e6b7c6..63cdba33 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/build.yml @@ -9,10 +9,6 @@ on: branches: - dev - master - - - - jobs: build: @@ -35,4 +31,4 @@ jobs: - name: Install NDK run: echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install "ndk;20.0.5594570" --sdk_root=${ANDROID_SDK_ROOT} - name: Build with Gradle - run: ./gradlew build check + run: ./gradlew build diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..34d4609b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,28 @@ +name: Testing Workflow + +on: + push: + branches: + - dev + - master + pull_request: + branches: + - dev + - master + + +jobs: + test: + + runs-on: [ubuntu-18.04] + + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Run unit tests + run: ./gradlew check + - name: upload code coverage + run: bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index dc7be7b6..0e93cb75 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,9 @@ [![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-) -![Tests](https://img.shields.io/github/workflow/status/OpenMined/KotlinSyft/Tests) -![Coverage](https://img.shields.io/codecov/c/github/OpenMined/KotlinSyft) -![Android CI](https://github.com/OpenMined/KotlinSyft/workflows/Android%20CI/badge.svg) +![Tests](https://img.shields.io/github/workflow/status/OpenMined/KotlinSyft/tests) +![Coverage](https://img.shields.io/codecov/c/github/OpenMined/KotlinSyft/dev) +![build](https://github.com/OpenMined/KotlinSyft/workflows/Android%20CI/badge.svg) ![License](https://img.shields.io/github/license/OpenMined/KotlinSyft) ![OpenCollective](https://img.shields.io/opencollective/all/openmined) diff --git a/build.gradle b/build.gradle index 2a51bf5a..9589667c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ buildscript { classpath ProjectDependencies.netflixPublishingPlugin classpath ProjectDependencies.netflixReleasePlugin classpath ProjectDependencies.netflixBintrayPlugin + classpath ProjectDependencies.jacoco // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 57100475..588e76d7 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -35,6 +35,7 @@ object Versions { const val netflixPublishing = "14.0.0" const val netflixRelease = "13.0.0" const val netflixBintray = "3.5.4" + const val jacocoVersion = "0.8.2" // Test const val junit = "1.1.1" @@ -57,6 +58,7 @@ object ProjectDependencies { Versions.netflixRelease const val netflixBintrayPlugin = "com.netflix.nebula:nebula-bintray-plugin:" + Versions.netflixBintray + const val jacoco = "org.jacoco:org.jacoco.core:" + Versions.jacocoVersion } object CommonDependencies { diff --git a/syftlib/build.gradle b/syftlib/build.gradle index d8f59227..63046c9c 100644 --- a/syftlib/build.gradle +++ b/syftlib/build.gradle @@ -2,13 +2,41 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlinx-serialization' apply plugin: 'kotlin-android-extensions' +apply plugin: 'jacoco' apply from: 'publish.gradle' +jacoco { + toolVersion = Versions.jacocoVersion +} + +check.finalizedBy "jacocoTestReport" + +tasks.withType(Test) { + useJUnitPlatform() +} + +task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { + + reports { + xml.enabled = true + html.enabled = true + } + + def fileFilter = [ '**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*' ] + def debugTree = fileTree(dir: "$project.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter) + def mainSrc = "$project.projectDir/src/main/java" + + sourceDirectories = files([mainSrc]) + classDirectories = files([debugTree]) + executionData = fileTree(dir: project.buildDir, includes: [ + 'jacoco/testDebugUnitTest.exec', 'outputs/code-coverage/connected/*coverage.ec' + ]) +} + android { compileSdkVersion Versions.compileSdk buildToolsVersion Versions.buildTools - defaultConfig { minSdkVersion Versions.minSdk targetSdkVersion Versions.targetSdk @@ -20,6 +48,9 @@ android { } buildTypes { + debug { + testCoverageEnabled = true + } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' @@ -32,6 +63,12 @@ android { testOptions { unitTests.returnDefaultValues = true + unitTests.all { + jacoco { + jacoco.includeNoLocationClasses = true + + } + } } lintOptions {