Maven使用三叶草插件运行两次单元测试 [英] Maven runs unit tests twice with clover plugin

查看:116
本文介绍了Maven使用三叶草插件运行两次单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的pom.xml中有此插件代码.如果我删除此插件,则Maven将不会运行两次单元测试.我只是想知道此插件的哪一部分使单元测试运行两次.

I have this plugin code in my pom.xml. If I remove this plugin then Maven won't run unit tests twice. I just wanted to know which part of this plugin makes the unit tests run twice.

<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-clover2-plugin</artifactId>
    <version>3.0.4</version>
    <configuration>
        <licenseLocation>/location/to/clover.license</licenseLocation>
        <generateXml>true</generateXml>
        <generateHtml>true</generateHtml>
    </configuration>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>instrument</goal>
            </goals>
        </execution>
        <execution>
            <id>main</id>
            <phase>verify</phase>
            <goals>
                <goal>instrument</goal>
                <goal>aggregate</goal>
                <goal>clover</goal>
            </goals>
        </execution>
        <execution>
            <id>site</id>
            <phase>pre-site</phase>
            <goals>
                <goal>instrument</goal>
                <goal>aggregate</goal>
            </goals>
        </execution>
    </executions>
</plugin>

推荐答案

三叶草插件使用检测到的类路径将生命周期分叉到test阶段.

The clover plugin forks a life cycle up to the test phase using the instrumented classpath.

您的标准生命周期将运行测试(通常在test阶段中使用surefire,但是在该阶段可能有多个执行或其他测试插件在调用测试)

Your standard life cycle will run the tests (typically using surefire in the test phase, but there could be multiple executions or other test plugins invoking tests in that phase)

然后三叶草出现,并要求它们再次运行.

Then clover comes along and asks for them to be run again.

现在是我的标准警告:

  • 代码覆盖率修改了按JVM规范合法的方式执行的字节代码.
  • 这种转换可能会导致在更新覆盖图时添加同步点.
  • 此类额外的同步点可能会限制JVM能够执行的操作的重新排序.
  • 还有其他一些与线程无关的更改,但解释起来很复杂.

如果仅在覆盖率处于打开状态的情况下运行测试用例,则您不能相信100%的通过率,因为覆盖率会掩盖错误

If you only ever run your test cases with coverage turned on, you cannot trust a 100% pass rate as coverage can mask bugs

相反,如果您从未在覆盖率未启用的情况下运行,则JVM体系结构的任何更改都可以突出显示您不知道的新错误.

Conversely, if you never run with coverage turned on, any change in JVM architecture can highlight new bugs that you didn't know.

  • 在不启用覆盖率的情况下通过测试=>可能还可以

  • Test passes with and without coverage turned on => probably ok

打开覆盖率测试通过,关闭时失败=>当心,此处有错误

Test passes with coverage turned on, fails when off => beware, bug here

测试通过且覆盖率处于关闭状态,如果=时机不是很关键,则失败,这时会出现bug,但是如果测试在生产环境中运行,则可能仅在-server完全优化热路径时显示bug

Test passes with coverage turned off, fails when on => if test is not timing critical then bug here, but if tests run on production environment bug may only show when -server fully optimises the hot paths

在未打开覆盖范围的情况下测试失败=>错误

Test fails with and without coverage turned on => bug

"斯蒂芬的黄金法则:

"Stephen's golden rule: Just run the damn tests twice"

这篇关于Maven使用三叶草插件运行两次单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆