简体   繁体   English

sonarqube显示0个单元测试的数据覆盖率

[英]sonarqube displays 0 unit tests data coverage

Trying to see unit test code coverage on sonar. 试图查看声纳上的单元测试代码覆盖率。 I am using Jacoco code coverage and able to get the code coverage for my project when I execute my code in eclipse. 我正在使用Jacoco代码覆盖率,并且在eclipse中执行代码时能够获得项目的代码覆盖率。 However while running in Jenkins, I get following messages and warnings as NO Tests to run , No Sources to compile 但是,在Jenkins中运行时,我收到以下消息和警告,因为没有要运行的测试,没有要编译的源

I can the some code coverage report on sonar but for unit tests it shows. 我可以提供一些关于声纳的代码覆盖率报告,但对于单元测试却可以显示。 How can Sonar display the coverage for unit tests? Sonar如何显示单元测试的覆盖范围? Also how can I eliminate the warning messages? 另外,如何消除警告消息?

Attaching my surefire and jacoco plugins and jebnkins console log 附加我的surefire和jacoco插件和jebnkins控制台日志

Kindly help 请帮助

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.6.4.201312101107</version>
  <executions>
    <execution>
      <id>prepare-unit-test-agent</id>
        <goals>
          <goal>prepare-agent</goal>
        </goals>
    </execution>
    <execution>
      <id>generate-unit-test-report</id>
        <goals>
          <goal>report</goal>
        </goals>
    </execution> 
  </executions>
</plugin> 


    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.12.4</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-testng</artifactId>
                        <version>2.12.4</version>
                    </dependency>
                </dependencies>
                <configuration>
                        <systemPropertyVariables>
                        <environment>${env.USER}</environment>
                    </systemPropertyVariables>          
                </configuration>    
            </plugin>

 [INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Project Test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ project test ---
[INFO] Deleting /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:prepare-agent (prepare-unit-test-agent) @ project test ---
[INFO] argLine set to -javaagent:/Users/ray1/.m2/repository/org/jacoco/org.jacoco.agent/0.6.4.201312101107/org.jacoco.agent-0.6.4.201312101107-runtime.jar=destfile=/Users/ray1/.jenkins/jobs/try10-aprl13/workspace/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ project test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ project test---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ project test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ project test ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ project test ---
[INFO] No tests to run.
[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (run-unit-tests) @ project test ---
[INFO] No tests to run.
[INFO] Skipping execution of surefire because it has already been run for this configuration
[JENKINS] Recording test results
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ project test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/target/project test-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.6.4.201312101107:report (generate-unit-test-report) @ project test ---
[INFO] Skipping JaCoCo execution due to missing execution data file
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ project test ---
[INFO] Installing /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/target/project test-0.0.1-SNAPSHOT.jar to /Users/ray1/.m2/repository/com/company/taf/project test/0.0.1-SNAPSHOT/project test-0.0.1-SNAPSHOT.jar
[INFO] Installing /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/pom.xml to /Users/ray1/.m2/repository/com/company/taf/project test/0.0.1-SNAPSHOT/project test-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.801 s
[INFO] Finished at: 2015-04-14T10:25:50-07:00
[INFO] Final Memory: 15M/81M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/pom.xml to com.company.inner/project test /0.0.1-SNAPSHOT/project test-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /Users/ray1/.jenkins/jobs/try10-aprl13/workspace/target/project test-0.0.1-SNAPSHOT.jar to com.company.inner/project test /0.0.1-SNAPSHOT/project test-0.0.1-SNAPSHOT.jar
channel stopped
Finished: SUCCESS

I had the similar issue, 0.0% coverage & no unit tests count on Sonar dashboard with SonarQube 6.7.2: Maven : 3.5.2, Java : 1.8, Jacoco : Worked with 7.0/7.9/8.0, OS : Windows 我遇到了类似的问题,使用SonarQube 6.7.2在Sonar仪表板上进行0.0%的覆盖率且没有任何单元测试:Maven:3.5.2,Java:1.8,Jacoco:使用7.0 / 7.9 / 8.0,OS:Windows

After a lot of struggle finding for correct solution, resolved issue with this configuration my parent pom looks like: 经过大量努力寻找正确的解决方案后,此父pom的配置问题已解决:

 <properties>
            <!--Sonar -->
            <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
            <sonar.language>java</sonar.language>

        </properties>

        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.5</source>
                            <target>1.5</target>
                        </configuration>
                    </plugin>

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

                    <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <version>0.7.9</version>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <append>true</append>
                        </configuration>
                        <executions>
                            <execution>
                                <id>agent</id>
                                <goals>
                                    <goal>prepare-agent</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

                </plugins>
            </pluginManagement>
        </build>

I've tried few other options like jacoco-aggregate & even creating a sub-module by including that in parent pom but nothing really worked & this is simple. 我尝试了其他一些选项,例如jacoco-aggregate ,甚至通过将其包含在父pom中来创建子模块,但实际上没有任何作用,这很简单。 I see in logs <sonar.jacoco.reportPath> is deprecated,but still works as is and seems like auto replaced on execution or can be manually updated to <sonar.jacoco.reportPaths> or latest. 我在日志中看到<sonar.jacoco.reportPath>已过时,但仍可以按原样运行,并且似乎在执行时自动替换,或者可以手动更新为<sonar.jacoco.reportPaths>或最新版本。 Once after doing setup start with mvn clean install then mvn org.jacoco:jacoco-maven-plugin:prepare-agent install & then do mvn sonar:sonar , this is what I've tried please let me know if some other best possible solution available.Hope this helps!! 这样设置后,一旦开始MVN再用干净的安装 MVN org.jacoco:jacoco - Maven的插件:准备代理安装 &然后做MVN声纳:声纳 ,这是我试过,请让我知道,如果其他一些最佳的解决方案希望有帮助! If not please post your question.. 如果没有,请发表您的问题。

you need to add this section to your parent pom.xml 您需要将此部分添加到您的父pom.xml

<properties>
    <!-- Properties to make sure we capture *all* coverage -->
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.language>java</sonar.language>
    <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
</properties>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SONARQUBE中的单元测试范围 - Unit Tests coverage in SONARQUBE SonarQube 始终显示 - 用于 Javascript 项目中的单元测试覆盖率 - SonarQube always displays - for Unit Tests Coverage in a Javascript project 库单元测试的覆盖率数据错误 - Wrong coverage data for unit tests of a library SonarQube不执行C#测试-单元测试覆盖率小部件显示0 - SonarQube does not execute C# tests - Unit Tests Coverage widget shows 0 为什么我没有在SonarQube中看到“单元测试覆盖”小部件的“单元测试成功”部分 - why am I not seeing “unit test success” section of “unit tests coverage” widget in SonarQube SonarQube 带有 Jest 单元测试 - SonarQube with Jest Unit Tests 如何让 SonarQube 分析单元测试中的代码气味,但不将它们计入覆盖率报告? - How do I get SonarQube to analyse Code Smells in unit tests but not count them for coverage reports? jacoco 插件的 SonarQube 覆盖率百分比显示为零,但可以看到单元测试的数量 - SonarQube coverage percentage with jacoco plugin shows zero percentage but hte number of unit tests are seen 100% 代码覆盖率; 数据类模型的单元测试 - 100% Code Coverage; Unit Tests for Data Class Models 单元测试,如何模拟返回空数据以获得100%的覆盖率 - Unit Tests, how to simulate return of null data to get a 100% coverage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM