Maven 2 mvn站点构建期间Maven2多项目Cobertura报告问题
我们有一个多项目,我们正在尝试运行Cobertura测试覆盖率报告,作为mvn站点构建的一部分。我可以让Cobertura在子项目上运行,但它错误地报告了0%的覆盖率,尽管报告仍然突出显示了单元测试所遇到的代码行 我们使用的是MVN2.0.8。我试过运行Maven 2 mvn站点构建期间Maven2多项目Cobertura报告问题,maven-2,code-coverage,maven-plugin,cobertura,Maven 2,Code Coverage,Maven Plugin,Cobertura,我们有一个多项目,我们正在尝试运行Cobertura测试覆盖率报告,作为mvn站点构建的一部分。我可以让Cobertura在子项目上运行,但它错误地报告了0%的覆盖率,尽管报告仍然突出显示了单元测试所遇到的代码行 我们使用的是MVN2.0.8。我试过运行mvn clean site,mvn clean site:stage和mvn clean package site。我知道测试正在运行,它们显示在surefire报告(txt/xml和站点报告)中。配置中是否缺少某些内容?Cobertura不适
mvn clean site
,mvn clean site:stage
和mvn clean package site
。我知道测试正在运行,它们显示在surefire报告(txt/xml和站点报告)中。配置中是否缺少某些内容?Cobertura不适合多项目吗
这是在parent.pom中:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<inherited>true</inherited>
</plugin>
</plugins>
</reporting>
报告如下所示:
我没有成功地让Cobertura将多个项目的报告合并起来。这通常是多项目报告的一个问题
我们一直在评估我们的指标报告解决方案。它似乎在跨项目(包括多项目)提供摘要度量方面做得很好。我怀疑您在编译阶段缺少对cobertura插件的执行,因此代码仅在测试运行后的站点生命周期中由报告插件检测。因此,测试运行不会被拾取,因为它们在未检测的代码上运行。更仔细地分析构建日志——如果我是对的,您会注意到surefire测试是在cobertura:instrument之前执行的 我的配置与您的配置类似,但除了在pluginManagement(像您一样)中指定clean Execution之外,我还在build plugins部分中明确指定了cobertura插件:
<build>
...
<plugins>
...
<plugin>
<inherited>true</inherited>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.plugin.version}</version>
</plugin>
</plugins>
</build>
...
...
真的
org.codehaus.mojo
cobertura maven插件
${cobertura.plugin.version}
我的配置很有效,所有Cobertura的东西都在全球组织范围的pom中,所有项目都将其用作父级
通过这种方式,项目在pom.xml中不指定任何与Cobertura相关的内容,但它们仍然会生成覆盖率报告。我实现的解决方案有点手动,但很有效。它由几个步骤组成,其中一个步骤是组合由Cobertura生成的几个.ser文件。这可以通过在maven任务中使用cobertura合并命令行工具来实现
根据您显示的输出,这些文件实际上没有插入指令,这表明只有3个文件被插入指令。@Marco是对的,通常仅通过maven无法实现这一点,因为maven cobertura插件缺少合并目标 您可以通过混合使用maven和ant目标来实现: 然而,如果您有一个项目处于测试中,则不需要合并。在测试项目中,您可以从测试项目中复制.ser文件和插入指令的类:
//in test project
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>copy-cobertura-data-from-project-under-test</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/../<project-under-test>/target/cobertura</directory>
<targetPath>${project.basedir}/target/cobertura</targetPath>
<includes>
<include>*.ser</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/../<project-under-test>/target/generated-classes/cobertura/</directory>
<targetPath>${project.basedir}/target/generated-classes/cobertura</targetPath>
<preservePath>true</preservePath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
//in parent project
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<format>xml</format>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
</plugin>
</plugins>
</reporting>
//在测试项目中
com.github.goldin
复制maven插件
0.2.5
从测试项目中复制cobertura数据
编译
复制
${project.basedir}/.//target/cobertura
${project.basedir}/target/cobertura
*赛尔先生
${project.basedir}/.//目标/生成的类/cobertura/
${project.basedir}/target/generated classes/cobertura
真的
//在父项目中
org.codehaus.mojo
cobertura maven插件
xml
真的
清洁的
org.codehaus.mojo
cobertura maven插件
${cobertura.version}
伙计,你需要一个新显示器!我几乎看不清那些班名。你说得对。此页面示例了此设置:。Ant用于调用cobertura merge,因为没有maven目标来调用merge。
<build>
...
<plugins>
...
<plugin>
<inherited>true</inherited>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.plugin.version}</version>
</plugin>
</plugins>
</build>
//in test project
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>copy-cobertura-data-from-project-under-test</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/../<project-under-test>/target/cobertura</directory>
<targetPath>${project.basedir}/target/cobertura</targetPath>
<includes>
<include>*.ser</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/../<project-under-test>/target/generated-classes/cobertura/</directory>
<targetPath>${project.basedir}/target/generated-classes/cobertura</targetPath>
<preservePath>true</preservePath>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
//in parent project
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<format>xml</format>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.version}</version>
</plugin>
</plugins>
</reporting>