android-analyzer icon indicating copy to clipboard operation
android-analyzer copied to clipboard

Code coverage not showing on Sonar

Open samasiMerini opened this issue 5 years ago • 10 comments

Code coverage not showing on Sonar : android { compileSdkVersion 28 buildToolsVersion "28.0.3" compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

defaultConfig {
    applicationId "com.oxyliom.oxyliomotp"
    minSdkVersion 20
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    externalNativeBuild {
        cmake {
            arguments '-DANDROID_STL=c++_static'
            abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
        }
    }

}
sourceSets {
    main {
        // let gradle pack the shared library into apk
        jniLibs.srcDirs = ['../distribution/gperf/lib']
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
    }

}

externalNativeBuild {
    cmake {
        version '3.10.2'
        path 'src/main/cpp/CMakeLists.txt'

    }
}
testOptions {
    unitTests.returnDefaultValues = true
    unitTests.includeAndroidResources = true
    unitTests.all {
        jacoco {
            includeNoLocationClasses = true
        }
    }
}

}

androidAnalyzer { applicationId = 'com.oxyliom.oxyliomotp' projectName = 'Oxyliom OTP' projectVersion = '1.0' unitTestCoverage = true packageName = 'com.oxyliom.oxyliomotp' buildVariant = 'debug'

}

samasiMerini avatar Nov 07 '19 14:11 samasiMerini

Interesting.

  1. Double-check your packageName argument, maybe it is different from your app id.
  2. If you are using Robolectic, make sure to add android.enableUnitTestBinaryResources=true to your gradle.properties file.
  3. The plugin does not support code coverage of instrumented tests, only unit tests.

Could you check the above points and get back to me, please? Also, a screenshot of the Sonarqube web interface would be helpful.

AndroideRob-zz avatar Nov 11 '19 07:11 AndroideRob-zz

  1. same packageName and app id .

i can find the androidAnalyzerJacoco folder in my project.

please find below the screenshoot of my coverage report and Sonarqube web interface

Capture d’écran 2019-11-13 à 10 17 16 Capture d’écran 2019-11-13 à 10 08 20

samasiMerini avatar Nov 13 '19 09:11 samasiMerini

Based on everything you provided, the coverage should be there.

Since the correct gets generated, my assumption is that the report is not sent to Sonarqube. This can potentially mean that the plugin resolved the report's path incorrectly.

I am looking into what might have caused it. In the meantime, could you set useDefaultExclusions = false, just in case all your >0% coverage is for excluded classes?

AndroideRob-zz avatar Nov 13 '19 17:11 AndroideRob-zz

I set useDefaultExclusions = false, but style the same bug just the number of new line to cover become duplicate. i think the problem is that the plugin resolved the report's path incorrectly.

samasiMerini avatar Nov 15 '19 08:11 samasiMerini

I have the same problem. Has anyone found a solution?

renatovieiradesouza avatar Jan 29 '20 14:01 renatovieiradesouza

I have the same problem. Has anyone found a solution?

no, in android studio i get 60% covered but in sonar show me 0% .

samasiMerini avatar Jan 29 '20 16:01 samasiMerini

Facing Same Problem Any Help so Far?

AmniX avatar Jan 30 '20 07:01 AmniX

Hi, i m solved using directly Sonar and not Android Analyzer. Add conf in task gradle sonar:

property "sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/jacocoProdDebugCoverage/jacocoProdDebugCoverage.xml"

Change dir for you and run.

renatovieiradesouza avatar Jan 30 '20 18:01 renatovieiradesouza

I am also having this Problem :-(

tampatamp avatar Feb 26 '20 13:02 tampatamp

I am also having this Problem :-(

Try do what i did. Work for me

renatovieiradesouza avatar Feb 26 '20 19:02 renatovieiradesouza