4

I have a spring-boot project and I am writing test using Karate and using Java Code Coverage maven plugin to generate a code coverage report and using SonarQube. I also have 2 Unit test. I am able to generate Jacoco report for unit test and karate test but SonarQube code-coverage percentage is not increasing.

First time I was just creating code-coverage for Unit test only and SonarQube coverage percentage was 0.7% then I generated a code-coverage report for both Unit test and Karate Test but sonarQube coverage percentage didn't increase it's still 0.7%.

I know about karate code-coverage index.html "target/site/jacoco/index.html" and it's generating as well.

But, I want it to reflect on SonarQube coverage percentage.

My application running on centOS server and all the test cases passed. BUILD successful.

My POM.xml file is as below.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <swagger.version>2.5.0</swagger.version>
    <!-- Sonar -->
    <sonar.junit.reportPaths>target/surefire-reports,target/failsafe-reports</sonar.junit.reportPaths>
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.reportPaths>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPaths>
    <sonar.jacoco.itReportPath>${project.build.directory}/jacoco-it.exec</sonar.jacoco.itReportPath>
</properties>

    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-apache</artifactId>
        <version>0.9.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>0.9.2</version>
        <scope>test</scope>
    </dependency>



<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <argLine>${surefireArgLine}
                    -Dfile.encoding=${project.build.sourceEncoding}</argLine>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>3.6.0.1398</version>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.22.1</version>
            <configuration>
                <argLine>${failsafeArgLine}
                    -Dfile.encoding=${project.build.sourceEncoding}</argLine>
            </configuration>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <id>pre-unit-test</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.reportPaths}</destFile>
                        <append>true</append>
                        <propertyName>surefireArgLine</propertyName>
                    </configuration>
                </execution>
                <execution>
                    <id>post-unit-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
                <execution>
                    <id>pre-integration-test</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.itReportPath}</destFile>
                        <append>true</append>
                        <propertyName>failsafeArgLine</propertyName>
                    </configuration>
                </execution>
                <execution>
                    <id>post-integration-test</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <dataFile>${sonar.jacoco.itReportPath}</dataFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

</build>

I expect SonarQubr coverage percentage should be more than 0.7%.

Kushang Bhatt
  • 83
  • 1
  • 6
  • dev of karate here - I'll leave this question to be answered by sonarqube experts :) – Peter Thomas Apr 30 '19 at 14:49
  • Did you have a look at the generated coverage file? – Jeroen Heier May 01 '19 at 17:46
  • @JeroenHeier yes, I look at the index.html file which is inside the site folder and coverage in that file is 0%. But when I do "mvn clean install sonar:sonar -Dsonar.host.url=http://123.456.78.09:9000 -Dsonar.login=admin -Dsonar.password=admin" it BUILD successfully. It create jacoco.exec and jacoco-it.exec and also jacoco-merged.exec inside the sonar folder. jacoco.exec is 453 KB and jacoco-it.exec is only 88 KB. Am I missing anything in the POM.xml file any configuration? – Kushang Bhatt May 03 '19 at 20:28

0 Answers0