diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d986064f..4bfdb509 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -31,4 +31,33 @@ jobs: run: ./gradlew build - name: Run Tests id: tests - run: ./gradlew test \ No newline at end of file + run: ./gradlew test + - name: Unit Test with Android Emulator Runner + uses: ReactiveCircus/android-emulator-runner@v2.14.3 + with: + api-level: 29 + script: ./gradlew testDebugUnitTest + - name: generate report + uses: actions/upload-artifact@v2 + with: + name: report + path: app/build/reports/coverage/debug +# - name: Download Test Reports Folder +# uses: actions/download-artifact@v2 +# with: +# name: report +# path: app/build/reports/coverage/debug +# - name: Upload Test Report +# uses: codecov/codecov-action@v2 +# with: +# token: ${{ secrets.CODECOV_REPO_UPLOAD_TOKEN }} +# files: "app/build/reports/coverage/debug/report.xml" +# name: codecov-skyflow-android +# verbose: true + - name: Codecov + uses: codecov/codecov-action@v2.1.0 + with: + token: ${{ secrets.CODECOV_REPO_UPLOAD_TOKEN }} + files: app/build/reports/coverage/debug/report.xml + name: codecov-skyflow-android + verbose: true diff --git a/Skyflow/build.gradle b/Skyflow/build.gradle index 18fb1739..04533bf4 100644 --- a/Skyflow/build.gradle +++ b/Skyflow/build.gradle @@ -2,10 +2,31 @@ plugins { id 'com.android.library' id 'kotlin-android' id 'maven-publish' + id 'jacoco' } apply plugin: 'kotlin-android' //group='com.github.skyflowapi' //version = rootProject.ext.versionName + +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: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) + def mainSrc = "${project.projectDir}/src/main/java" + + sourceDirectories.setFrom(files([mainSrc])) + classDirectories.setFrom(files([debugTree])) + executionData.setFrom(fileTree(dir: "$buildDir", includes: [ + "jacoco/testDebugUnitTest.exec", + "outputs/code-coverage/connected/*coverage.ec" + ])) +} + ext { mGroupId = "com.skyflowapi.android" mArtifactId = "skyflow-android-sdk" @@ -28,27 +49,32 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" } + testOptions { - unitTests { - includeAndroidResources = true - returnDefaultValues = true + unitTests.all { + jacoco { + includeNoLocationClasses = true + } } - + unitTests.returnDefaultValues = true } + buildTypes { + debug { + testCoverageEnabled true + } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } - } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '11' } } diff --git a/build.gradle b/build.gradle index 47fd4027..aa6ea9ef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.6.0-M1' + ext.kotlin_version = "1.4.21" + ext.jacocoVersion = '0.8.4' repositories { google() mavenCentral() @@ -10,6 +12,7 @@ buildscript { classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0' classpath "com.github.dcendents:android-maven-gradle-plugin:2.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jacoco:org.jacoco.core:$jacocoVersion" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }