我正在开发一个包含两个模块的库项目:主模块包含逻辑,我有一个测试模块,其中包含一些与主模块类相关的测试工具,以及来自主模块的测试。我需要将测试移到测试模块以避免循环依赖。确定。
现在,我需要在运行测试(包含在测试模块中)后生成核心模块的覆盖范围。我的jacoco
配置是这样的:
task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
reports {
xml.enabled = true
html.enabled = true
}
jacocoClasspath = configurations['androidJacocoAnt']
def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${rootProject.projectDir}/test-module/build/intermediates/classes/debug", excludes: fileFilter)
def debugMainTree = fileTree(dir: "${rootProject.projectDir}/main-module/build/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${rootProject.projectDir}/test-module/src/main/java"
def mainMainSrc = "${rootProject.projectDir}/main-module/src/main/java"
sourceDirectories = files([mainSrc])
additionalSourceDirs = files([mainMainSrc])
classDirectories = files([debugTree])
additionalClassDirs = files([debugMainTree])
executionData = files "${buildDir}/jacoco/testDebugUnitTest.exec"
}
所有课程都出现在报告中,但覆盖率为0%。我收到一些关于输出的警告,说的是:
[ant:jacocoReport] Classes in bundle 'test-module' do no match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class my/class/from/MainModule does not match.
我查看了intermediates
个文件夹,试图找出测试占用主类文件的位置,但没有成功。
顺便说一句,这是一个Android库项目(内部发布了2个工件)。我正在使用Gradle 2.8。