科贝图拉和码头

发布于 2024-12-14 05:06:39 字数 585 浏览 4 评论 0原文

我正在尝试使用 cobertura 在 Jetty 上运行我的网络应用程序时获取覆盖率报告。 我们已经使用 Surefire 插件运行 cobertura 来进行单元测试。 我们还配置了故障安全插件来运行我们的集成测试。

我已经(手动)装备了我的战争并部署了它。

当仅使用集成测试配置文件运行 mvn verify 时,cobertura 似乎正在工作,因为我在 eclipse 控制台中收到各种新警告(我从那里运行 jetty)可能是因为字节码已更改通过科贝尔图拉。 但即使在码头服务器上调用 "stop" 时,我也无法写入 .ser 文件。

运行 mvn cobertura:cobertura 时,我确实得到了一个 .ser 文件,并且在我的 web 应用程序的 target/site 目录下生成了一份报告。该报告显示覆盖率为 0%,因为 cobertura:cobertura 未运行任何测试。

如何使用故障安全使 cobertura 运行我的集成测试? 还有其他建议吗?

谢谢, 本

I'm trying to get coverage report when running my webapp on Jetty, using cobertura.
We already have cobertura running for unit-tests by using the surefire plugin.
We also have the failsafe plugin configured for running our integration-tests.

I've already (manually) instrumented my war and deployed it.

When running mvn verify with integration-tests only profile, it seems cobertura is working because I get all kind of new warnings in eclipse console (i'm running jetty from there) probably because byte-code was changed by cobertura.
But I don't get the .ser file to be written, even when calling "stop" on the jetty server.

I do get a .ser file when running mvn cobertura:cobertura and a report is generated under target/site directory of my webapp. The report shows 0% coverage because cobertura:cobertura doesn't run any tests.

How can I run my integration-tests using the failsafe make cobertura to work?
Any other suggestions?

Thanks,
Ben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2024-12-21 05:06:39

我通过使用 cobertura-it 插件解决了这个问题。它扩展了原始的 cobertura 插件并允许使用仅报告目标。此外,我必须运行两个单独的命令(见下文)来测试和生成报告(合并到 1 个命令不起作用)。这是我的插件配置。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-it-maven-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <formats>
            <format>html</format>
        </formats>
        <check>
            <haltOnFailure>false</haltOnFailure>
        </check>
    </configuration>
    <executions>
        <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>cobertura</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>            
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.4.2.v20110526</version>
    <configuration>
        <stopKey>aaaaaaaaaaaaa</stopKey>
        <stopPort>8085</stopPort>
    </configuration>
    <executions>
        <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <daemon>true</daemon>
                <classesDirectory>target/generated-classes/cobertura</classesDirectory>
            </configuration>
        </execution>
        <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>net.sourceforge.cobertura</groupId>
            <artifactId>cobertura</artifactId>
            <version>1.9.4.1</version>
        </dependency>
    </dependencies>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.10</version>
    <executions>
        <execution>
              <id>integration-test</id>
              <phase>integration-test</phase>
              <goals>
                  <goal>integration-test</goal>
              </goals>
        </execution>
        <execution>
            <id>verify</id>
            <phase>verify</phase>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

所以我运行这个:
mvn clean verify

请注意,Jetty 停止后,有一些 cobertura 消息:

[INFO] -------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------
[INFO] Total time: 1 minute 13 seconds
[INFO] Finished at: Sun Nov 13 12:58:29 ICT 2011
[INFO] Final Memory: 86M/204M
[INFO] -------------------------------------------------------
2011-11-13 12:58:29.765:WARN::4 threads could not be stopped
Flushing results...
Flushing results done
Cobertura: Loaded information on 342 classes.
Cobertura: Saved information on 342 classes.

最后,我使用 mvn site 生成报告。这是我的报告配置

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <!-- An error on version 2.8 -->
            <version>2.7</version>
            <configuration>
                <reportsDirectories>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory>
                </reportsDirectories>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <!-- An error that takes long time to generate this report -->
                <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>dependencies</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-it-maven-plugin</artifactId>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

I solved this issue by using cobertura-it plugin. It extends the original cobertura plugin and allows to use report-only goal. In addition, I must run two separate commands (see below) to test and generate reports (merging to 1 command does not work). Here is my plugin configuration.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-it-maven-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <formats>
            <format>html</format>
        </formats>
        <check>
            <haltOnFailure>false</haltOnFailure>
        </check>
    </configuration>
    <executions>
        <execution>
            <id>pre-integration-test</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>cobertura</goal>
            </goals>
        </execution>
    </executions>
</plugin>
<plugin>            
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>7.4.2.v20110526</version>
    <configuration>
        <stopKey>aaaaaaaaaaaaa</stopKey>
        <stopPort>8085</stopPort>
    </configuration>
    <executions>
        <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <scanIntervalSeconds>0</scanIntervalSeconds>
                <daemon>true</daemon>
                <classesDirectory>target/generated-classes/cobertura</classesDirectory>
            </configuration>
        </execution>
        <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>net.sourceforge.cobertura</groupId>
            <artifactId>cobertura</artifactId>
            <version>1.9.4.1</version>
        </dependency>
    </dependencies>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.10</version>
    <executions>
        <execution>
              <id>integration-test</id>
              <phase>integration-test</phase>
              <goals>
                  <goal>integration-test</goal>
              </goals>
        </execution>
        <execution>
            <id>verify</id>
            <phase>verify</phase>
            <goals>
                <goal>verify</goal>
            </goals>
        </execution>
    </executions>
 </plugin>

So I run this:
mvn clean verify

Note that after Jetty is stopped, there is some cobertura messages:

[INFO] -------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] -------------------------------------------------------
[INFO] Total time: 1 minute 13 seconds
[INFO] Finished at: Sun Nov 13 12:58:29 ICT 2011
[INFO] Final Memory: 86M/204M
[INFO] -------------------------------------------------------
2011-11-13 12:58:29.765:WARN::4 threads could not be stopped
Flushing results...
Flushing results done
Cobertura: Loaded information on 342 classes.
Cobertura: Saved information on 342 classes.

Finally, I use mvn site to generate reports. Here is my report configuration

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <!-- An error on version 2.8 -->
            <version>2.7</version>
            <configuration>
                <reportsDirectories>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory>
                </reportsDirectories>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-project-info-reports-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <!-- An error that takes long time to generate this report -->
                <dependencyLocationsEnabled>false</dependencyLocationsEnabled>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>dependencies</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-it-maven-plugin</artifactId>
            <configuration>
                <formats>
                    <format>html</format>
                    <format>xml</format>
                </formats>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>
热情消退 2024-12-21 05:06:39

Perhaps you need some <execution> tag to your cobertura-maven-plugin plugin config.
There are some examples on http://mojo.codehaus.org/cobertura-maven-plugin/instrumentingDeploymentArtifact.html but this answer looks better: What is the proper way to use Cobertura with Maven 3.0.2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文