简体   繁体   中英

Sonar skips integration tests

I need to analyse code via Sonar using Gradle and I have some strange problem which I cannot handle. I have the following project structure

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

And Sonar analyse only test directory by default and integration-test directory if I change sonar.test property to /src/integration-test, but I want to analyze this two directories together and I actually dont know how to do it. Below we have my sonarqube task properties from gradle.build file.

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"
    }
}

What I noticed is that when I run gradle build there would be integrationTest.exec and test.exec in /build/jacoco/ directory, but in case I run gradle sonarqube with default sonar.test property there would be only test.exec, and from other hand when I run gradle sonarqube with sonar.test=/src/integration-test there would be both test.exec and integrationTest.exec.

Dont you know how to analyze unit and integration test in one run?

I think you can add this to your Gradle:

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

Just use += to add more tests/sources. More information and examples are here .

EDIT:

Add report paths too! Properties are named:

sonar.surefire.reportsPath - test.testResultsDir (if the directory exists)

sonar.junit.reportsPath - test.testResultsDir (if the directory exists)

EDIT:

I rewrite your code and set sources for testing in one line, check it with your structure

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"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM