2
我有Sonar分析的Android項目。我看到所有的問題,但沒有通過單元測試覆蓋。我嘗試了很多東西,但仍然無法正常工作。當我調用「gradlew createDebugCoverageReport」時,它會在build/reports/coverage/debug目錄中創建包含很多文件的目錄,如report.xml和index.html,其中包含測試覆蓋率數據。但是在覆蓋範圍內的Sonar中,我收到類似'這個組件沒有覆蓋細節'的消息。我如何得到它的工作?Android將單元測試覆蓋率添加到聲納中
命令序列:
gradlew clean assemble
gradlew createDebugCoverageReport
gradlew sonarRunner
的build.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'
}
感謝您的幫助。它現在運作良好。 – user1816532
我該如何擴展這個解決方案,以便它也可以用於Instrumentation測試(AndroidJUnit4)?爲了最好,如果它是在一個報告中? – user1816532
那麼你究竟想讓它工作?如果它關於通過或失敗的測試聲納也支持他們,並且sonarqube官方頁面上有關於如何整合它的文檔。它比添加覆蓋報告更容易,您只需定義測試代碼的路徑 – hrskrs