getting empty jacoco report using android studio
ajay4dhurvanshi opened this issue · 1 comments
Dear All,
I have written unit test cases for simple code for which I want to generate jacoco report by writing a chunk of code in the Gradle file of an android studio.
Below code written in top-level Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://maven.google.com/"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.4'
classpath "net.saliman:gradle-cobertura-plugin:3.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
}
}
and below code written in app-level Gradle:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
testOptions{
unitTests.all{
jacoco{
includeNoLocationClasses = true
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
}
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 = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/code-coverage/connected/*coverage.ec"
])
}
after implementing these codes, I have executed gradlew jacocoTestReport task due to this test cases are running but empty jacoco report is generating like below.
Anyone came across this type of issue then pls help me to resolve this issue.
Thanks,
Ajay D
Take a look at this repo: https://github.com/vanniktech/Emoji I have coverage there