【问题标题】:Sonar skips integration testsSonar 跳过集成测试
【发布时间】:2016-12-06 15:56:08
【问题描述】:

我需要使用 Gradle 通过 Sonar 分析代码,但我遇到了一些我无法处理的奇怪问题。我有以下项目结构

-java
  |-src
    |-main
    |-test
    |-integration-test

如果我将sonar.test属性更改为/src/integration-test,Sonar默认只分析测试目录和集成测试目录,但我想一起分析这两个目录,我实际上不知道该怎么做。下面我们有来自 gradle.build 文件的我的 sonarqube 任务属性。

sonarqube {
    properties {
        property "sonar.projectName", "projectName"
        property "sonar.projectKey", "org.sonarqube:projectName"
        property "sonar.host.url", "http://sonar.doesntmetter"
        property "sonar.java.coveragePlugin", "jacoco"
        property "sonar.junit.reportsPath", "build/test-results/test"
        property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
        property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec"
    property "sonar.login", "admin"
    property "sonar.password", "admin"
    }
}

我注意到的是,当我运行 gradle build 时,/build/jacoco/ 目录中会有 integrationTest.exec 和 test.exec,但如果我使用默认的 sonar.test 属性运行 gradle sonarqube,则只有测试。 exec,另一方面,当我使用 sonar.test=/src/integration-test 运行 gradle sonarqube 时,将同时存在 test.exec 和 integrationTest.exec。

你不知道如何一次性分析单元和集成测试吗?

【问题讨论】:

    标签: java gradle sonarqube jacoco sonarqube-scan


    【解决方案1】:

    我认为您可以将其添加到您的 Gradle 中:

    sonarqube {
        properties {
            properties["sonar.sources"] += sourceSets.custom.allSource.srcDirs
            properties["sonar.tests"] += sourceSets.integTest.allSource.srcDirs
        }
    }
    

    只需使用+= 添加更多测试/源。 更多信息和例子是here

    编辑:

    也添加报告路径!属性命名:

    sonar.surefire.reportsPath - test.testResultsDir(如果目录存在)

    sonar.junit.reportsPath - test.testResultsDir(如果目录存在)

    编辑:

    我重写了你的代码并在一行中设置了测试源,检查你的结构

    sonarqube {
        properties {
            property "sonar.projectName", "projectName"
            property "sonar.projectKey", "projectKey"
            property "sonar.host.url", "http://itsprettyprivate"
            property "sonar.java.coveragePlugin", "jacoco"
            // Or add it via += to properties, it is up to you ;)
            property "sonar.sources", "src/java,src/test,src/integration-test"
            //Tells SonarQube where the unit tests execution reports are
            property "sonar.junit.reportsPath", "build/test-results/test"
            //Tells SonarQube where the unit tests code coverage report is
            property "sonar.jacoco.reportPath", "build/jacoco/test.exec"
            //Tells SonarQube where the integration tests code coverage report is
            property "sonar.jacoco.itReportPath", "build/jacoco/integrationTest.exec"
            property "sonar.login", "admin"
            property "sonar.password", "password"
        }
    }
    

    【讨论】:

    • 不幸的是它没有帮助,我仍然只有单元测试的统计数据
    • 您只丢失了报告但运行了测试?然后需要为reportPath添加更多属性:sonar.surefire.reportsPathsonar.junit.reportsPath
    • 实际上集成测试没有运行
    • 我应该为集成测试添加与 sonar.tests 相同的报告路径吗?
    • 请把新配置发给你 :) 我会试着看看并贴出来
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 2016-01-16
    • 2023-03-19
    • 2014-07-03
    相关资源
    最近更新 更多