sonarqube具有androidTest和test covarage
我正在尝试在我的Android项目中设置报告。我目前无法在sonar UI中显示所有测试类,覆盖率以百分比显示,目前只有来自sonarqube具有androidTest和test covarage,android,unit-testing,gradle,sonarqube,jacoco,Android,Unit Testing,Gradle,Sonarqube,Jacoco,我正在尝试在我的Android项目中设置报告。我目前无法在sonar UI中显示所有测试类,覆盖率以百分比显示,目前只有来自app/src/test/的单元测试显示为单元测试 我的项目有一个包含单元测试的测试文件夹app/src/test/,我有一个包含android单元、集成和UI测试的androidTest文件夹app/src/androidTest/。当我通过gradle运行所有测试时,android gradle插件会生成build/jacoco/testDebugUnitTest.ex
app/src/test/
的单元测试显示为单元测试
我的项目有一个包含单元测试的测试文件夹app/src/test/
,我有一个包含android单元、集成和UI测试的androidTest文件夹app/src/androidTest/
。当我通过gradle运行所有测试时,android gradle插件会生成build/jacoco/testDebugUnitTest.exec
和build/test results/debug/test-*test.xml
,其中包含测试文件夹中单元测试的jacoco结果和覆盖率报告。android gradle插件还生成build/outputs/code coverage/connected/coverage.ec
和build/outputs/androidTest results/connected/TEST-*TEST.xml
包含androidTest文件夹中的结果和覆盖率报告
在我的build.gradle中,我可以指定sonar插件的属性
sonarqube {
properties {
property "sonar.sources", "src/main/java,src/main/res"
property "sonar.tests", "src/test/java,src/androidTest/java"
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.jacoco.reportPath", "${project.buildDir}/jacoco/testDebugUnitTest.exec"
property 'sonar.jacoco.itReportPath', "${project.buildDir}/outputs/code-coverage/connected/coverage.ec"
property "sonar.junit.reportsPath", "${project.buildDir}/test-results/debug" // path to junit reports
}
}
通过sonar.junit.reportsPath
我可以指定将哪个xml报告发送到sonarqube服务器。当我将其更改为build/outputs/androidTest results/connected
时,我会在仪表板上将androidTest显示为单元测试。有没有办法使sonar插件在两个目录中都能看到或将结果合并在一起?在修复之前,您唯一的选择是编写一个任务,将测试结果文件复制到一个地方,并将其配置为sonar.junit.reportsPath
,如下所示:
task combineTestResultsForSonarqube {
group = "Reporting"
def modules = ["app", "and", "other", "modules"];
doLast {
modules.each { module ->
File combined = file("${module}/build/combined-test-results")
if (combined.exists()) {
combined.deleteDir()
}
combined.mkdirs();
def testDirs = [file("${module}/build/test-results/debug/"),
file("${module}/build/outputs/androidTest-results/connected/")];
testDirs.each { testDir ->
if (!testDir.exists()) {
logging.captureStandardOutput LogLevel.WARN
println "WARNING: ignoring non-existant ${testDir.path}"
return;
}
files(testDir.listFiles()).each { file ->
new File(combined, file.getName()) << file.text
}
}
}
}
}
任务组合StreetResultsForSonarQube{
group=“报告”
def模块=[“应用程序”、“和”、“其他”、“模块”];
多拉斯特{
modules.each{module->
文件组合=文件(${module}/build/combined test results)
if(组合的.exists()){
composited.deleteDir()
}
组合的.mkdirs();
def testDirs=[文件(“${module}/build/test results/debug/”,
文件(“${module}/build/outputs/androidtestresults/connected/”);
testDirs.each{testDir->
如果(!testDir.exists()){
logging.captureStandardOutput LogLevel.WARN
println“警告:忽略不存在的${testDir.path}”
返回;
}
文件(testDir.listFiles())。每个{file->
新文件(组合,File.getName())虽然这可能会在SonarQube测试列表中添加UI测试,但它不会增加您的覆盖率%,也不会表明方法已被覆盖。有什么解决方案吗?@Elias如果您使用Jacoco进行检测和代码覆盖,则已设置,因为SonarQube的较新版本合并了单元和检测测试中的Jacoco覆盖率数据。我是however不知道其他覆盖率插件也可以这样做。我们使用的是SonarQube v6,我想它是最新的?我传递了以下属性:属性“sonar.java.coveragePlugin”、“jacoco”属性“sonar.jacoco.reportPath”、“build/jacoco/testProductionMinSdk19DebugUnitTest.exec”//junit覆盖率报告属性“sonar.junit.reportsPath”,“build/testresults/productionMinSdk19Debug/”//junit报告属性“sonar.android.lint.report”的路径,“/build/outputs/lint-results-productionMinSdk19Debug.xml”//lint报告的路径