[英]Sonar Jacoco not considering Kotlin androidTest (integration test case) in coverage
我为我的 android 项目编写了本地和集成测试用例。 使用Kotlin
(1.4.21) Robolectric
(4.5.1), sonar
(2.7.1), Jacoco
(maven plugin 0.8.2)
问题是Sonar
和Jacoco
没有考虑用Kotlin
编写的androidTest
(集成测试用例)进行代码覆盖但是声纳显示其他测试用例的正确覆盖率,例如 -
java 单元测试用例 -> 工作
koltin 单元测试用例 -> 工作
java集成测试用例->工作
kotlin 集成测试用例 ->不工作
虽然我检查了我为声纳设置的路径,但一切都是正确的。
properties['sonar.java.binaries'] = files("${buildDir}/intermediates/javac/universalDebug/classes")
properties["sonar.java.binaries"] += files("${buildDir}/tmp/kotlin-classes/universalDebug/")
properties['sonar.java.test.binaries'] = files("${buildDir}/intermediates/javac/universalDebugAndroidTest/classes")
properties['sonar.java.test.binaries'] += files("${buildDir}/tmp/kotlin-classes/universalDebugAndroidTest/")
我已经完成了其他 stackoverflow 问题,但没有发现同样的问题。 所以,我无法找出声纳没有显示我用 Kotlin 编写的集成测试用例的覆盖率的问题。
提前致谢
您可能需要执行以下操作
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}
请注意,Java 11 的一些问题可能会导致您的测试失败,因此您可能还想排除jdk.internal
,如下所示
tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
或者有点冗长的选项,但有效:
subprojects {
pluginManager.withPlugin("com.android.library"){
android.testOptions.unitTests.all {
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
}
}
pluginManager.withPlugin("com.android.application"){
android.testOptions.unitTests.all {
jacoco {
includeNoLocationClasses = true
excludes = ['jdk.internal.*']
}
}
}
apply plugin: 'jacoco'
}
如果可能的话,我建议你也升级你的 jacoco 和 sonar 插件版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.