试图在声纳上查看单元测试代码覆盖率。我正在使用Jacoco代码覆盖,并且能够在我在eclipse中执行代码时获得项目的代码覆盖率。然而,在Jenkins中运行时,我收到以下消息和警告,因为没有测试运行,没有要编译的源
我可以在声纳上进行一些代码覆盖率报告,但是对于它显示的单元测试。 Sonar如何显示单元测试的覆盖范围?另外我如何消除警告信息?
附上我的万无一失和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)
我有类似的问题,0.0%覆盖范围&amp;使用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>
我尝试过其他一些选项,例如 jacoco-aggregate &amp;甚至创建一个子模块,通过将其包含在父pom中,但没有真正起作用的&amp;这很简单。我在日志中看到<sonar.jacoco.reportPath>
已被弃用,但仍然按原样运行,似乎在执行时自动替换,或者可以手动更新为<sonar.jacoco.reportPaths>
或最新。在使用 mvn clean install 进行安装后,然后 mvn org.jacoco:jacoco-maven-plugin:prepare-agent install &amp;然后做 mvn声纳:声纳,这就是我试过的,请告诉我是否有其他最好的可用解决方案。希望这有帮助!!如果没有,请发表您的问题..
答案 1 :(得分:0)
您需要将此部分添加到父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>