单元测试通过Maven,但未通过Cobertura:"期望分支目标65处的堆栈图帧"

UpA*_*ght 19 java cobertura spring-mvc maven spring-mvc-test

我最近在我的Java/Spring-MVC项目中添加了Cobertura插件.奇怪的是,我的所有单元测试都在通过,并且当Maven进行初始测试运行时它们仍然通过,但是当Cobertura尝试运行测试时,它们都会失败,并显示相同的错误消息:

Expecting a stackmap frame at branch target 65 in method xxx.xxxx.xxxx.xxxx;)V at offset 40
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会发生这种情况,甚至不知道如何解决这个问题.我搜索过互联网,但没有发现任何类似的问题.我使用JUnit和spring-test-mvc进行测试.

谁看过这个吗?

UpA*_*ght 19

当然,在问到这个问题之后我找到了答案,即使我之前搜索了很长时间......

问题是Cobertura在使用Java 1.7时遇到了麻烦.您必须将以下行添加到pom.xml:

<argLine>-XX:-UseSplitVerifier</argLine>
Run Code Online (Sandbox Code Playgroud)

这在配置元素中.这是整个Cobertura部分:

     <plugin>
        <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <argLine>-XX:-UseSplitVerifier</argLine>
                <formats>
                    <format>xml</format>
                </formats>
            </configuration>
            <executions>
                <execution>
                    <phase>test</phase>
                    <goals>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
       </plugin>
Run Code Online (Sandbox Code Playgroud)

现在一切都按预期工作.

  • Cobertura 2.6也解决了这个问题. (6认同)

jpr*_*ism 5

通过使用新插件修复

                  <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>cobertura-maven-plugin</artifactId>
                        <version>2.7</version>
                        <configuration>
                            <formats>
                                <format>xml</format>
                            </formats>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>cobertura</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
Run Code Online (Sandbox Code Playgroud)