From 9fe7ff98c8db08781302e871f1a04e3069f6eb8a Mon Sep 17 00:00:00 2001 From: Suraj s Date: Thu, 19 Oct 2023 10:16:38 -0700 Subject: [PATCH] Add Kover Code Coverage (#2794) * build : add kover code coverage gradle plugin * ci : add kover gradle task in github action --- .github/workflows/test.yml | 33 ++++++++++++++++++++++++++++- app/build.gradle.kts | 43 ++++++++++++++++++++++++++++++++++++++ build.gradle.kts | 22 +++++++++++++++++++ gradle/libs.versions.toml | 3 ++- 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 17c7b9238a..2c76b23dec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,4 +30,35 @@ jobs: ${{ runner.os }}-gradle- - name: Run unit tests - run: ./gradlew testDebugUnitTest \ No newline at end of file + run: ./gradlew testDebugUnitTest + + code_coverage: + needs: test + runs-on: ubuntu-latest + steps: + - name: Checkout GIT + uses: actions/checkout@v4 + + - name: Setup Java SDK + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '18' + + - name: Enable Gradle Wrapper caching (optimization) + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Code Coverage + run: ./gradlew koverHtmlReport + + - name: Upload Code Coverage Report + uses: actions/upload-artifact@v2 + with: + name: code-coverage-report + path: app/build/artifacts/reports/kover/coverageResults/index.html diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6e67ba430b..97452c7ee4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -186,3 +186,46 @@ dependencies { lintChecks(libs.slack.lint.compose) } + +dependencies { + koverReport { + defaults { + mergeWith("debug") + html { + onCheck = false + setReportDir(layout.buildDirectory.dir("artifacts/reports/kover/coverageResults")) + } + } + } + + kover(projects.ivyBase) + kover(projects.ivyData) + kover(projects.ivyDomain) + kover(projects.ivyNavigation) + kover(projects.ivyResources) + kover(projects.ivyWidgetBase) + kover(projects.screenAttributions) + kover(projects.screenBalance) + kover(projects.screenBudgets) + kover(projects.screenCategories) + kover(projects.screenContributors) + kover(projects.screenExchangeRates) + kover(projects.screenFeatures) + kover(projects.screenHome) + kover(projects.screenImportData) + kover(projects.screenLoans) + kover(projects.screenMain) + kover(projects.screenOnboarding) + kover(projects.screenPiechart) + kover(projects.screenPlannedPayments) + kover(projects.screenReleases) + kover(projects.screenReports) + kover(projects.screenSearch) + kover(projects.screenSettings) + kover(projects.screenTransaction) + kover(projects.screenTransactions) + kover(projects.tempLegacyCode) + kover(projects.tempOldDesign) + kover(projects.widgetAddTransaction) + kover(projects.widgetBalance) +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index cd90d64d6f..c1eb48b31a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,28 @@ plugins { id("ivy.detekt") alias(libs.plugins.gradleWrapperUpgrade) + + alias(libs.plugins.koverPlugin) +} + +subprojects { + apply(plugin = "org.jetbrains.kotlinx.kover") + koverReport { + // filters for all report types of all build variants + filters { + excludes { + classes( + "*Activity", + "*Activity\$*", + "*.BuildConfig", + "dagger.hilt.*", + "hilt_aggregated_deps.*", + "*.Hilt_*" + ) + annotatedBy("@Composable") + } + } + } } wrapperUpgrade { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 80e0ff9388..d3ca57251e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -205,4 +205,5 @@ opencsv = [ ] [plugins] -gradleWrapperUpgrade = { id = "org.gradle.wrapper-upgrade", version = "0.11.4" } \ No newline at end of file +gradleWrapperUpgrade = { id = "org.gradle.wrapper-upgrade", version = "0.11.4" } +koverPlugin = { id = "org.jetbrains.kotlinx.kover", version = "0.7.4" } \ No newline at end of file