Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 061471da authored by Jonathan Klee's avatar Jonathan Klee
Browse files

Merge branch '0000-a15-execute-tests-all-the-time' into 'main'

Introduce Jacoco

See merge request !642
parents 38aaed96 5c59149f
Loading
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -43,14 +43,18 @@ test:
    - if: $CI_MERGE_REQUEST_ID
      when: always
  script:
    - ./gradlew test -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl"
    - ./gradlew test jacocoDebugReport -PtestAccountName="$testAccountName" -PtestAccountPwd="$testAccountPwd" -PtestServerUrl="$testServerUrl"
  artifacts:
    when: always
    paths:
      - app/build/test-results/*/TEST-*.xml
      - app/build/reports/tests/*
      - app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml
    reports:
      junit: app/build/test-results/*/TEST-*.xml
      coverage_report:
        coverage_format: jacoco
        path: app/build/reports/jacoco/jacocoDebugReport/jacocoDebugReport.xml

# Default lint configuration for debug builds
# Manual as we don't want to run them generally for debug builds
+70 −1
Original line number Diff line number Diff line
@@ -9,6 +9,11 @@ plugins {
    id 'com.google.dagger.hilt.android'
    id 'kotlin-allopen'
    id 'kotlin-parcelize'
    id 'jacoco'
}

jacoco {
    toolVersion = libs.versions.jacoco.get()
}

def versionMajor = 2
@@ -42,6 +47,30 @@ def getSentryDsn = { ->
    return properties.getProperty('SENTRY_DSN')
}

def jacocoFileFilter = [
        '**/R.class',
        '**/R$*',
        '**/BuildConfig.*',
        '**/Manifest*.*',
        '**/*Test*.*',
        '**/*_ViewBinding*.*',
        '**/*Binding.class',
        '**/*BindingImpl.class',
        '**/Dagger*.*',
        '**/*MembersInjector*.*',
        '**/*_Factory*.*',
        '**/*_Provide*Factory*.*',
        '**/*_GeneratedInjector*.*',
        '**/*Hilt*.*'
]

tasks.withType(Test).configureEach {
    jacoco {
        includeNoLocationClasses = true
        excludes = ['jdk.internal.*']
    }
}

android {
    compileSdk = 35

@@ -166,6 +195,47 @@ android {
    }
}

android.applicationVariants.configureEach { variant ->
    def variantCap = variant.name.capitalize()
    def unitTestTaskName = "test${variantCap}UnitTest"
    def unitTestTask = tasks.findByName(unitTestTaskName)
    if (unitTestTask == null) {
        return
    }

    tasks.register("jacoco${variantCap}Report", JacocoReport) {
        dependsOn(unitTestTask)
        group = "verification"
        description = "Generates Jacoco coverage report for the ${variant.name} build."

        reports {
            xml.required = true
            html.required = true
        }

        def javaClasses = fileTree("${buildDir}/intermediates/javac/${variant.name}/classes") {
            exclude jacocoFileFilter
        }
        def kotlinClasses = fileTree("${buildDir}/tmp/kotlin-classes/${variant.name}") {
            exclude jacocoFileFilter
        }

        classDirectories.from = files(javaClasses, kotlinClasses)

        def sourceDirs = variant.sourceSets.collect { sourceSet ->
            def dirs = []
            dirs.addAll(sourceSet.java.srcDirs)
            if (sourceSet.hasProperty('kotlin')) {
                dirs.addAll(sourceSet.kotlin.srcDirs)
            }
            return dirs
        }.flatten()

        sourceDirectories.from = files(sourceDirs)
        executionData.from = file("${buildDir}/jacoco/${unitTestTaskName}.exec")
    }
}

allOpen {
    // allows mocking for classes w/o directly opening them for release builds
    annotation 'foundation.e.apps.OpenClass'
@@ -280,4 +350,3 @@ def retrieveKey(String keyName, String defaultValue) {

    return properties.getProperty(keyName, defaultValue)
}
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ jacksonDataformatYaml = "2.17.0"
jsoup = "1.17.2"
junit = "4.13.2"
junitVersion = "1.2.1"
jacoco = "0.8.11"
kotlin = "2.1.0"
hilt = "2.54"
kotlinxCoroutinesAndroid = "1.10.1"