Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing sonarqube显示0单元测试数据覆盖率_Unit Testing_Maven_Jenkins_Sonarqube_Jacoco - Fatal编程技术网

Unit testing sonarqube显示0单元测试数据覆盖率

Unit testing sonarqube显示0单元测试数据覆盖率,unit-testing,maven,jenkins,sonarqube,jacoco,Unit Testing,Maven,Jenkins,Sonarqube,Jacoco,尝试查看声纳上的单元测试代码覆盖率。我使用的是Jacoco代码覆盖率,当我在eclipse中执行代码时,我能够获得项目的代码覆盖率。然而,在Jenkins中运行时,我收到以下消息和警告:没有要运行的测试,没有要编译的源代码 我可以在sonar上看到一些代码覆盖率报告,但对于单元测试,它会显示。声纳如何显示单元测试的覆盖范围?还有,如何消除警告消息 附加我的surefire和jacoco插件以及jebnkins控制台日志 好心帮忙 <plugin> <groupId>o

尝试查看声纳上的单元测试代码覆盖率。我使用的是Jacoco代码覆盖率,当我在eclipse中执行代码时,我能够获得项目的代码覆盖率。然而,在Jenkins中运行时,我收到以下消息和警告:没有要运行的测试,没有要编译的源代码

我可以在sonar上看到一些代码覆盖率报告,但对于单元测试,它会显示。声纳如何显示单元测试的覆盖范围?还有,如何消除警告消息

附加我的surefire和jacoco插件以及jebnkins控制台日志

好心帮忙

<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

我也有类似的问题,0.0%的覆盖率&SonarQube 6.7.2的Sonar仪表板上没有单元测试: Maven:3.5.2, Java:1.8, Jacoco:使用7.0/7.9/8.0, 操作系统:Windows

在为找到正确的解决方案进行了大量努力之后,解决了此配置的问题我的父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>

我尝试过其他一些选项,比如jacocoaggregate&甚至通过在父pom中包含子模块来创建子模块,但没有任何效果&这很简单。我在日志中看到的是不推荐使用的,但仍按原样工作,似乎在执行时自动替换,或者可以手动更新到或更新到最新版本。安装完成后,从mvn clean安装开始,然后是mvn org.jacoco:jacoco maven插件:准备代理安装,然后执行mvn sonar:sonar,这是我尝试过的,请告诉我是否有其他最好的解决方案可用。希望这有帮助!!如果没有,请发布您的问题。

您需要将此部分添加到您的家长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>

可能重复的我可以看到测试没有运行,因此不会创建jacoco结果文件。关于maven+surefire或failsafe+jacoco配置,我推荐在该线程上找到的步骤: