zhangkevd

zhangkevd

Member Since 8 years ago

Experience Points
11
follower
Lessons Completed
63
follow
Lessons Completed
739
stars
Best Reply Awards
35
repos

3 contributions in the last year

Pinned
⚡ GreenDroid is a development library for the Android platform. It makes UI developments easier and consistent through your applications.
⚡ An image download-and-cacher that also knows how to efficiently generate and retrieve thumbnails of various sizes.
⚡ OpenGG's blog
⚡ 基于mina框架的Socket服务器搭建
Activity
Nov
26
1 week ago
started
started time in 1 week ago
started
started time in 1 week ago
Nov
20
2 weeks ago
Nov
19
2 weeks ago
started
started time in 2 weeks ago
Oct
22
1 month ago
Activity icon
issue

zhangkevd issue comment robolectric/robolectric

zhangkevd
zhangkevd

when run unittest with RobolectricTestRunner,jacoco generate coverage report with zero data

Description

I want to generate coverage report for a library project。Found that if run unit test case with RobolectricTestRunner I could not get coverage data in the coverage report。 My library project build.gradle is below:

apply plugin: 'com.android.library' apply plugin: 'jacoco'

android { compileSdkVersion 29

defaultConfig {
    minSdkVersion 15
    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
    }
}
testBuildType 'debug'

}

jacoco { toolVersion = "0.8.5" } task jacocoTestReport(type: JacocoReport) { group = "Reporting" description = "Generate Jacoco coverage reports after running tests." def debugTree = fileTree(dir: "${buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes", excludes: ['/R*.class', '/*MainActivity.class', ]) def coverageSourceDirs = "${project.projectDir}/src/main/java" reports { xml.enabled = true html.enabled = true } classDirectories = files(debugTree) sourceDirectories = files(coverageSourceDirs) executionData = files("$buildDir/jacoco/testDebugUnitTest.exec") }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'androidx.test:core:1.0.0'
testImplementation 'org.mockito:mockito-core:2.28.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

}

library project has a only one simple java class: package com.example.mylibrary;

public class Hello {

public static String hello() {
    return "hello";
}

}

unittest case is below: package com.example.mylibrary;

import android.os.Build;

import org.junit.Test; import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**

  • Example local unit test, which will execute on the development machine (host).
  • @see Testing documentation */ //@RunWith(RobolectricTestRunner.class) //@Config(manifest= Config.NONE,sdk = Build.VERSION_CODES.P) public class ExampleUnitTest { @Test public void hello() { assertTrue(Hello.hello() == "hello"); } }

I run test and get report like this in terminal

./gradlew testDebugUnitTest jacocoTestReport

get test result report and coverage report image

but if run the case with RobolectricTestRunner,I get zero coverage in report。 @RunWith(RobolectricTestRunner.class) @Config(manifest= Config.NONE,sdk = Build.VERSION_CODES.P) public class ExampleUnitTest { @Test public void hello() { assertTrue(Hello.hello() == "hello"); } }

much thks for any idea

zhangkevd
zhangkevd

Any update on this issue? I'm facing the same thing.

Oct
9
1 month ago
started
started time in 1 month ago
Sep
11
2 months ago
started
started time in 2 months ago
started
started time in 2 months ago