stevesaliman / gradle-cobertura-plugin

Gradle Cobertura Plugin
119 stars 50 forks source link

Android integration tests reports for test classes in src/androidTest folder #110

Open Code1942 opened 8 years ago

Code1942 commented 8 years ago

I am trying to generate integration tests reports for my Android Project. I get the below Error

Unable to instrument file /home/EmployeeDirectory/app/build/instrumented_classes/com/directory/employee/employeedirectory/EmployeeList.class java.lang.NoClassDefFoundError: android/app/Application

Request you to please share the details if that is possible. Here is my build.gradle

" buildscript { repositories { maven { url 'https://maven.fabric.io/public' } maven { url "https://oss.sonatype.org/content/repositories/snapshots" }

}

dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
    classpath "net.saliman:gradle-cobertura-plugin:2.3.1"
}

}

plugins { id "org.sonarqube" version "1.2" }

apply plugin: 'com.android.application' apply plugin: 'io.fabric' apply plugin: 'com.google.gms.google-services'

apply plugin: 'net.saliman.cobertura' apply from: '../sonarqube.gradle'

def APP_VERSION = "1.0.0" ext.set('AppVersion', APP_VERSION)

repositories { maven { url 'https://maven.fabric.io/public' } }

android { compileSdkVersion 23 buildToolsVersion "23.0.2"

testOptions {
    unitTests.returnDefaultValues = true
}
defaultConfig {
    applicationId "com.directory.employee.employeedirectory"
    testApplicationId "com.directory.employee.employeedirectory.test"
    minSdkVersion 18
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

lintOptions {
    // if true, stop the gradle build if errors are found
    abortOnError false
}

buildTypes {
    release {
    }
    debug {
        testCoverageEnabled true
    }
}

productFlavors {
}

}

dependencies { compile 'com.android.support:support-annotations:23.0.1' compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.1'

compile 'com.google.android.gms:play-services-analytics:8.3.0'
//classpath 'io.fabric.tools.gradle:1.+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') {
    transitive = true;
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.2@aar') {
    transitive = true;
}

testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19'

androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support:support-annotations:23.0.1'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

}

cobertura { coverageFormats = ['html', 'xml']
coverageIgnoreTrivial = true
coverageIgnores = ['org.slf4j.Logger.*']
coverageReportDir = new File("$buildDir/reports/cobertura") }

crashlytics { enableNdk true androidNdkOut 'src/main/obj' androidNdkLibsOut 'src/main/libs' }

"

stevesaliman commented 8 years ago

I know that things work a little differently when the plugin is applied to Android projects, but I don't have Android experience, so I'm not going to be much help here. Maybe someone following this project with more Android experience could help out?

Sorry I can't give more information.

stevesaliman commented 7 years ago

You may need to add an auxiliaryClasspath entry to your cobertura block. Issue #124 has an example of this. I'm not sure exactly what you need to find the class in your situation, but you could try adding auxiliaryClasspath = files(project.android.getBootClasspath()).

shekharhimanshu commented 7 years ago

I was trying to generate integration tests (the one inside androidTest folder) report as well but every time the cobertura would report 0 as code coverage.

Here is my gradle script

apply plugin: 'net.saliman.cobertura'
cobertura {
    coverageFormats = ['html', 'xml']
    auxiliaryClasspath = files(project.android.getBootClasspath())

    coverageExcludes = ['.*\\.R.*',
                        '.*\\.BuildConfig',
                        '.*\\.Manifest']

    coverageTestTasks {
        project.tasks.matching {
            it.name == "connected${androidVariant.capitalize()}AndroidTest"
        }
    }

    coverageReportDir = new File("${buildDir}/reports/cobertura")
}

And I run it like this, gradle clean cobertura. However, this way I am not able to get the correct results. (gradle run doesn't throw any error either) Any ideas as to what I might be doing wrong here?