android - 即使在构建成功后,代码覆盖率报告也显示为 0%
问题描述
我在 android studio 中使用 jacoco 和 sonar 生成代码覆盖率报告。我已经按照https://www.youtube.com/watch?v=acxwRaxoGAo的视频成功执行了这些命令。
我在执行后构建成功,但在声纳服务器中显示代码覆盖率 0.0%。
Project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'https://maven.google.com' }
maven { url 'https://mvnrepository.com/artifact/' }
maven { url 'https://maven.fabric.io/public' }
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven {
url "https://plugins.gradle.org/m2/"
}
google()
//maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:3.0.0'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
//classpath 'io.fabric.tools:gradle:1.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven { url 'https://mvnrepository.com/artifact/' }
maven { url 'https://maven.fabric.io/public' }
mavenCentral()
flatDir {
dirs 'libs'
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url 'https://jitpack.io' }
google()
}
}
apply plugin: "org.sonarqube"
task clean(type: Delete) {
delete rootProject.buildDir
}
应用等级:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 27
//buildToolsVersion '25.0.3'
defaultConfig {
applicationId "com.test.dev.MyProject"
minSdkVersion 15
targetSdkVersion 27
versionCode 3
versionName "3.2"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled true
}
}
sonarqube {
properties {
property "sonar.projectName", "MyProjectSonar"
property "sonar.projectKey", "com.test.dev.MyProject"
property "sonar.sources", "src/main/java"
property "sonar.language", "java"
property "sonar.sourceEncoding", "UTF-8"
//property "sonar.surefire.reportsPath", "target/surefire-reports"
property "sonar.jacoco.reportPaths", "target/jacoco.exec"
property "sonar.binaries", "target/classes"
//property "sonar.cpd.exclusions", "src/main/java/com/**/*.java"
}
}
}
jacoco {
toolVersion "0.8.0"
}
dependencies {
implementation(name: 'circleimageview-2.1.0', ext: 'aar')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
// Testing-only dependencies
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
// Testing-only dependencies
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
// required if you want to use Mockito for Android tests
androidTestImplementation 'org.mockito:mockito-android:2.7.22'
// Force usage of dependencies in the test app, since it is internally used by the runner module.
androidTestImplementation 'com.android.support:support-annotations:27.1.1'
}
apply plugin: 'com.google.gms.google-services'
谁能告诉我我是否需要做任何其他更改。我还在我的 gradle 文件中添加了 jacoco 插件。但在声纳服务器中,代码覆盖率仍显示为 0.0%
解决方案
推荐阅读
- git - 重新创建“中等”格式以在 git log 中使用
- r - X 和 Y 上具有 2 个变量的散点图基因共表达
- laravel - 为 Eloquent 模型 Laravel 创建构造函数
- java - 级联 bean 验证 2.0 不适用于 Map 中的嵌套对象
- android - Android Studio 如何强制所有设备从 Play 商店下载新版本
- html - 如何在表格中居中条形码图像?
- rabbitmq - Rabbitmq:无法登录rabbitmq
- javascript - CSS 过渡不适用于 jQuery 的 .toggleClass()
- windows - 用户模式下 ntdll.dll 中的 windows 本机函数移至内核模式
- javascript - 如何获取数据表中 2 个不同列的 2 个参数?