我们已经有了一个多项目,我们正在试图运行Cobertura测试的复盖范围的报告的一部分,我们会为了寻求简便的网站建设。我可以得到Cobertura运行上的儿童的项目,但是它错误地报告0%的复盖率,即使这些报告仍突出的代码行被击中通过该单元的测试。

我们正在使用会为了寻求简便2.0.8.我已经尝试运行 mvn clean site, mvn clean site:stagemvn clean package site.我知道的测试正在运行,它们在稳赚不赔的报告(两txt/xml和网站报告)。我失去了一些东西在配置?不Cobertura不工作的权利与multiprojects?

这是在父母。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>

我已经尝试运行,它并没有以下的孩子。劲歌:

    <reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        </plugin>
    </plugins>
</reporting>

我得到这个输出的建立:

...
[INFO] [cobertura:instrument]
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Instrumenting 3 files to C:\workspaces\sandbox\CommonJsf\target\generated-classes\cobertura
Cobertura: Saved information on 3 classes.
Instrument time: 186ms

[INFO] Instrumentation was successful.
...
[INFO] Generating "Cobertura Test Coverage" report.
[INFO] Cobertura 1.9 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Cobertura: Loaded information on 3 classes.
Report time: 481ms

[INFO] Cobertura Report generation was successful.

该报告看起来是这样的:cobertura report

有帮助吗?

解决方案

我怀疑你是缺少一个执行cobertura插在编制阶段,以便代码只得到检测报告的插件,在该网站的生命周期,之后的测试运行。所以测试运行是不是捡起来,因为它们运行在非仪表代码。分析建立记录更仔细地-如果我是对的,你会注意到,正确的测试之前执行cobertura:文书。

我的配置是你的相似,但除了指定的清洁exectution在pluginManagement(像你一样),我指定的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>

我的配置么工作,以及所有Cobertura的东西是全球组织范围pom,其所有项目中使用作为父母。

这种方法的项目不指定任何Cobertura有关在他们的pom.xml's,但他们仍然生成的复盖范围的报告。

其他提示

我还没有成功,在获得Cobertura合并报告从多项目。这已经是一个问题,在大多项目的报告。

我们已经评估 声纳 作为一个解决方案为我们的指标的报告。它似乎要做大量的工作提供摘要指标项目,其中包括多proijects.

该方案实施过我是有点手册,但工作。它包括几个步骤中的一个步骤是结合几种。ser文件,这些文件产生的Cobertura.这可以通过使用cobertura合并命令行工具的内部专家的任务。

根据本输出显示的是,该文件实际上并未被检测,它告诉只有3个文件检测.

@马可是正确的,它是不可能实现这通常通过专家只有作为的家cobertura插件是缺少一个合并的目标。

你可以实现它通过一种混合行家和蚂蚁目标: http://thomassundberg.wordpress.com/2012/02/18/test-coverage-in-a-multi-module-maven-project/

尽管如此,在这种情况下你有一个单一项目undertest,没有必要进行合并。你可以,在试验项目,复制。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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top