Skip to content

Commit

Permalink
JaCoCo Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Jan 9, 2025
1 parent 204eb9b commit 6d7a0fa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ jobs:

- name: Run unit tests
run: |
./gradlew :stream-video-android-ui-compose:testDebugUnitTest --scan --stacktrace
./gradlew :stream-video-android-core:testDebugUnitTest --scan --stacktrace
./gradlew :stream-video-android-ui-compose:testDebugUnitTest :stream-video-android-ui-compose:testCoverage --scan --stacktrace
./gradlew :stream-video-android-core:testDebugUnitTest :stream-video-android-core:testCoverage --scan --stacktrace
- name: Unit tests core results
uses: actions/upload-artifact@v4
Expand Down
63 changes: 63 additions & 0 deletions scripts/coverage.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
if (!rootProject.ext.sonar.ignoreModules.contains(name)) {
apply plugin: 'jacoco'
apply plugin: "org.sonarqube"

def testTask = "testDebugUnitTest"
def jacocoResults = "${buildDir}/reports/jacoco/report.xml"

if (hasProperty('android')) {
android {
buildTypes {
debug {
testCoverageEnabled = true
enableUnitTestCoverage = true
enableAndroidTestCoverage true
}
}
}
}

afterEvaluate {
tasks.withType(Test).configureEach {
jacoco.includeNoLocationClasses = true
jacoco.excludes = [
'jdk.internal.*',
'androidx.core.*',
'com.android.*',
'android.*'
]
}

tasks.register("testCoverage", JacocoReport) {
dependsOn testTask

reports {
xml.required.set(true)
xml.outputLocation.set(file(jacocoResults))
}

executionData.setFrom(fileTree(dir: buildDir, includes: [
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
]))

sourceDirectories.setFrom(files([
"src/main/kotlin"
]))

classDirectories.setFrom(files([
fileTree(
dir: "${buildDir}/tmp/kotlin-classes/debug",
excludes: rootProject.ext.sonar.excludeFilter
)
]))
}
}

sonarqube {
properties {
property "sonar.junit.reportPaths", "${buildDir}/test-results/${testTask}"
property "sonar.coverage.jacoco.xmlReportPaths", jacocoResults
property "sonar.sources", "src/main/kotlin"
}
}
}

0 comments on commit 6d7a0fa

Please sign in to comment.