[英]jacoco code coverage of integration tests in a separate module in Netbeans
[英]Jacoco code coverage with Sonar and maven for integration tests in separate module
我已经使用SonarQube和Jacoco配置我的项目以进行代码覆盖。 除了一件事,一切都很好。 我在许多maven子模块中划分了项目:
project (pom.xml) -
|-moduleA (no pom here)
| |- it (pom.xml) - integration tests for "impl" module
| |- impl (pom.xml) - implementaion + Unit tests
|-moduelB
| |- it (pom.xml) - integration tests for "impl" module
| |- impl (pom.xml) - implementaion + Unit tests
|-moduleC ...
我使用以下命令开始构建:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent -Dmaven.compiler.debug=true install sonar:sonar
问题是,Jacoco可轻松支持在同一个模块内的单元测试覆盖率(所以在我的情况下,单元测试impl
模块),但不能从分析覆盖率it
模块,本身不包含任何实现类。 它只包含impl
模块的集成测试。 我很清楚为什么它不起作用。 我在Jacoco日志中得到这样的信息:
No JaCoCo analysis of project coverage can be done since there is no class files.
我在moduleA / it / pom.xml中定义了sonar.java.binaries
属性,如下所示:
<properties>
<sonar.java.binaries>../impl/target/classes</sonar.java.binaries>
</properties>
it
覆盖率分析仍然失败,但Jacoco日志中的消息变为:
[INFO] Analysing D:\project\moduleA\it\target\jacoco.exec
[WARNING] Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
我必须提到D:\\project\\moduleA\\it\\target\\jacoco.exec
文件存在。 我还检查了D:\\project\\moduleA\\impl\\target\\classes
中的编译类包含调试数据(所有行,变量和源)。
我在sonar.java.binaries
中尝试不同的路径,但结果总是一样的。 我试过了:
../impl/target/classes
../../impl/target/classes
../../../impl/target/classes
../impl/target
...
如何配置Jacoco(声纳)以允许它在与jacoco.exec文件相关的不同maven子模块中查找类二进制文件?
基于这个问题 ,我使用了JaCoCo的ant任务库的Maven Ant插件 ,它允许更丰富的包含树:
<project ...>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</dependency>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>report-it-coverage</id>
<phase>post-integration-test</phase>
<goals><goal>run</goal></goals>
<configuration>
<skip>${skipITs}</skip>
<target name="report-it-coverage">
<taskdef name="jacoco-report" classname="org.jacoco.ant.ReportTask" classpathref="maven.plugin.classpath" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.runtime.classpath" />
<available file="${jacoco.it-coverage.data}" property="jacoco.exec.file.exists" />
<if>
<equals arg1="${jacoco.exec.file.exists}" arg2="true" />
<then>
<echo>Analyzing ITs coverage data from '${jacoco.it-coverage.data}'</echo>
<jacoco-report>
<executiondata>
<file file="${jacoco.it-coverage.data}" />
</executiondata>
<structure name="ROOT">
<classfiles>
<fileset dir="${project.basedir}/${project.parent.relativePath}">
<include name="**/target/classes/my/company/package/**/*.class" />
<exclude name="**/target/classes/my/test/glue/**/*" />
</fileset>
</classfiles>
</structure>
<html destdir="${project.reporting.outputDirectory}/jacoco-it" />
<xml destfile="${project.build.directory}/jacoco.xml" />
</jacoco-report>
</then>
<else>
<echo>Missing ITs coverage data file '${jacoco.it-coverage.data}'</echo>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.