Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.ClassFormatError:类文件中的方法代码长度75567无效_Java_Mockito_Cobertura_Powermockito - Fatal编程技术网

java.lang.ClassFormatError:类文件中的方法代码长度75567无效

java.lang.ClassFormatError:类文件中的方法代码长度75567无效,java,mockito,cobertura,powermockito,Java,Mockito,Cobertura,Powermockito,向聪明人问好 我正在使用cobertura和mockito以及powermocktio来获得代码覆盖率。 我的机器上安装了1.7java版本 当我在eclipse中运行junit测试用例时,所有测试用例都通过了。 但是当我跑的时候 mvn cobertura:cobertura 我得到以下错误 java.lang.ClassFormatError:类中的方法代码长度75567无效 文件 我研究并了解到这是因为JVM为metod分配了内存大小 我的测试类是指一个具有非常庞大的静态方法的遗留类。由于

向聪明人问好

我正在使用cobertura和mockito以及powermocktio来获得代码覆盖率。 我的机器上安装了1.7java版本

当我在eclipse中运行junit测试用例时,所有测试用例都通过了。 但是当我跑的时候

mvn cobertura:cobertura

我得到以下错误

java.lang.ClassFormatError:类中的方法代码长度75567无效 文件

我研究并了解到这是因为JVM为metod分配了内存大小

我的测试类是指一个具有非常庞大的静态方法的遗留类。由于影响太多,我无法去触摸遗留类或主类进行折射。

任何在不涉及主要类的情况下消除此异常的想法都将受到欢迎

谢谢
Pradeep

您可以尝试为您的测试环境禁用字节码验证(通过在JVM启动选项中添加-noverify)

当然,这不是您在生产环境中应该做的事情;但是考虑到您的需求,这可能是您获得测试+覆盖率的唯一机会


但是接下来:准备好迎接更多丑陋的惊喜。Powermock(ito)因打破覆盖测量而“出名”。事实上,我认为让这样一个设置可靠运行并创建可靠覆盖率的机会非常小

简单,从Cobertura工具中排除遗留类。使用Maven时,类似于以下内容:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <instrumentation>
            <excludes>
                <exclude>aaa/**/Legacy.class</exclude>
            </excludes>
        </instrumentation>
    </configuration>
</plugin>

org.codehaus.mojo
cobertura maven插件
2.6
aaa/**/Legacy.class

非常感谢,罗杰。起初我以为排除在外不包括保险范围。但这对我很有效。