【发布时间】:2016-05-24 23:54:24
【问题描述】:
我有一个由 Sonar 分析的 Android 项目。我看到了所有问题,但单元测试没有覆盖。我尝试了很多东西,但仍然无法正常工作。当我调用“gradlew createDebugCoverageReport”时,它会在 build/reports/coverage/debug 中创建目录,其中包含许多文件,例如 report.xml 和 index.html,其中包含测试覆盖率数据。但是在覆盖范围下的声纳中,我收到类似“此组件没有覆盖详细信息”的消息。我怎样才能让它工作?
命令序列:
gradlew clean assemble
gradlew createDebugCoverageReport
gradlew sonarRunner
构建.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "cz.meteocar.unit"
minSdkVersion 16
targetSdkVersion 20
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
testCoverageEnabled = true
}
}
}
apply plugin: 'sonar-runner'
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000" // Address of Sonar server
property "sonar.sources", "src/main/java" // Sources
property "sonar.projectName", "Meteocar" // Name of your project
property "sonar.projectVersion", "1.0.2" // Version of your project
property "sonar.projectDescription", "Sonar" // Description of your project
property "sonar.junit.reportsPath", "build/reports/coverage/"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/mbassador-1.2.0.jar')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:20.0.0'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'com.jjoe64:graphview:4.0.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.powermock:powermock-api-mockito:1.6.1'
testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.1'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.1'
testCompile 'org.powermock:powermock-module-junit4:1.6.1'
testCompile 'org.json:json:20140107'
}
【问题讨论】:
标签: android unit-testing sonarqube android-gradle-plugin build.gradle