我必须在我的Android测试中设置代码覆盖率报告,然后在声纳中发布它们。我已经读过没有可以做到的工具和插件。我正在使用gradle脚本,我尝试jacoco插件,cobertura,但没有结果。有什么方法可以解决它吗?我也试着像Gradle jacoco code coverage - Then publish/show in Jenkins
那样做答案 0 :(得分:1)
带有代码覆盖率和声纳的build.gradle示例
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId 'com.example.coverage'
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName '1.0'
testHandleProfiling true
testFunctionalTest true
}
buildTypes {
debug {
testCoverageEnabled true
}
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
apply plugin: 'sonar-runner'
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'LICENSE.txt'
}
}
sonarRunner {
sonarProperties {
property "sonar.projectKey", "coverage-example"
property "sonar.projectName", "Coverage Example"
property "sonar.projectVersion", "1.0"
property "sonar.sources", "src/main/java"
property "sonar.binaries", "build"
property "sonar.test", "src/androidTest/java"
property "sonar.profile", "Sonar way"
property "sonar.language", "java"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.dynamicAnalysis", "reuseReports"
property "sonar.junit.reportsPath", "build/outputs/reports/coverage/debug"
property "sonar.cobertura.reportPath", "build/outputs/reports/coverage/debug/cobertura.xml"
property "sonar.java.coveragePlugin", "cobertura"
property "sonar.host.url", "http://localhost:9099"
}
}
gradlew clean assembleDebug createDebugCoverageReport
应用程序/生成/输出/报告/覆盖/调试/ report.xml将
python cover2cover.py app/build/outputs/reports/coverage/debug/report.xml src/main/java > app/build/outputs/reports/coverage/debug/cobertura.xml && cp app/build/outputs/androidTest-results/connected/* app/build/outputs/reports/coverage/debug/
gradlew sonarRunner