Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coverage report says zero coverage on android with gradle

I've been unable to get code coverage to work on any of my android projects.

To simplify things I created a new project (selected empty activity). Added a new utility class to the the project in src/main/java.

I then created a unit test for it in src/androidTest/java.

Updated the gradle file to enable coverage.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.michaelkrussel.coverageapp"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }

    jacoco {
        version "0.7.1.201405082137"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
             testCoverageEnabled true
        }
    }
}

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

I ran the tests then using ./gradlew createDebugCoverageReport. The unit test shows that the test I created passed, but the coverage report reports zero coverage.

I assume I'm either missing something in the gradle file or not running the correct gradle task, but I cannot figure out what.

like image 929
Michael Krussel Avatar asked Mar 11 '15 17:03

Michael Krussel


1 Answers

I'm using this configuration in my project and work fine!

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "br.com.acs.app"
        minSdkVersion 18
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        testApplicationId "br.com.acs.app.test"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

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

    androidTestCompile 'junit:junit:4.11'
    androidTestCompile('com.android.support.test:testing-support-lib:0.1') {
        exclude group: 'junit' 
    }
}
like image 153
Anderson K Avatar answered Sep 30 '22 12:09

Anderson K