Jacoco为现有耳朵运行时出现"IllegalStateException:类输入不兼容的执行数据…"的异常 [英] “IllegalStateException: Incompatible execution data for class in…” exception from Jacoco when run for an existing ear

查看:239
本文介绍了Jacoco为现有耳朵运行时出现"IllegalStateException:类输入不兼容的执行数据…"的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Arquillian和TestNG测试传统的大型EAR(app.ear)应用程序.为了运行测试,我将可测试的war文件(test.war)添加到现有的app.ear中,并远程部署在WildFly 10服务器上.

I’m trying to test a legacy big fat EAR (app.ear) application using Arquillian and TestNG. To run the test I have added the testable war file (test.war) in to the existing app.ear and deployed on WildFly 10 server remotely.

@Deployment
public static EnterpriseArchive createDeployment(){
    return ShrinkWrap.createFromZipFile(EnterpriseArchive.class, new File("../earapp/target/earapp-0.0.1-SNAPSHOT.ear"))
            .addAsModule(Testable.archiveToTest(ShrinkWrap.create(WebArchive.class, "test.war")
                    .addClass(CurrencyConverterTest.class)
                    .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")));
}

我的下一部分要求是在运行测试后获取代码覆盖率报告.为此,我正在使用Jacoco并与Jacoco Maven插件一起运行.

The next part of my requirement is to get code coverage report after the tests are run. For that I’m using Jacoco and running it with Jacoco Maven Plugin.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.7.201606060606</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
</plugin>

app.ear已部署,即使测试也运行良好,但是当涉及到生成报告时,Jacoco失败并出现异常 " IllegalStateException:Jacoco中类的执行数据不兼容…… …"

The app.ear gets deployed and the even the tests are running fine but when it comes to generate the report the Jacoco is failing with and exception "IllegalStateException: Incompatible execution data for class in Jacoco ………"

仅包含测试用例的类才出现异常.如果我使用Jacoco Maven插件中的排除标签排除了该类( CurrencyConverterTest.class ),则该异常消失了,但Jacoco生成的报告中没有数据.另外,我已经检查了jacoco.exec,据我所知它包含有效数据.

The exception is coming only for the class which contains the test cases. If I exclude that class (CurrencyConverterTest.class) using exclusion tag in Jacoco Maven Plugin the exception goes away but the reports generated by Jacoco contains no data. Also I’ve checked jacoco.exec and as far as I can say it contains valid data.

由于我无法共享正在使用的专有代码,因此我在github上创建了三个简单的项目来模拟相同的代码.

Since I cannot share the proprietary code I’m working with, I’ve created three simple projects on github to emulate the same.

  • 项目1(currencycoverter):该项目具有一个无状态ejb,其远程接口具有三种方法.
  • 项目2( earapp ):该项目使用项目1作为ejb模块来创建ear文件.
  • 项目3( eartest ):此项目测试项目2生成的耳朵.
  • Project 1 (currencycoverter): This project has one stateless ejb with a remote interface having three methods.
  • Project 2 (earapp): This project creates the ear file using project 1 as ejb module.
  • Project 3 (eartest): This project test the ear generated by project 2.

在我看来,Jacoco代码中存在一些错误,但我也可能错了.请帮帮我.

To me it looks like that there is some bug in the Jacoco code but I might be wrong also. Please help me out.

更新:构建在git repo上共享的项目的步骤

第1步:检出所有三个项目,并作为eclipse项目导入eclipse.

Step 1: Check out all the three projects and import into eclipse as eclipse projects.

步骤2:为项目1(currencyconverter)运行maven命令 clean instll

Step 2: Run maven command clean instll for project 1 (currencyconverter)

第3步:为项目2(earapp)运行maven命令 clean package .这将在目标目录中创建一个ear文件.

Step 3: Run maven command clean package for project 2 (earapp). This will create an ear file in the target directory.

步骤4:在本地计算机上以独立模式启动WildFly 10.

Step 4: Start a WildFly 10 in standalone mode on the local machine.

第5步:为项目3(最早)运行maven命令 clean install .这将使用第3步中生成的耳朵并将其部署到WildFly 10应用服务器中并运行测试.

Step 5: Run maven command clean install for project 3 (eartest). This will use the ear generated in step 3 and deploy it in WildFly 10 application server and run the tests.

推荐答案

不幸的是,您的示例无法构建:

Unfortunately your example can't be built:

[ERROR] Failed to execute goal on project eartest:
Could not resolve dependencies for project com.sg.eartest:eartest:jar:0.0.1-SNAPSHOT:
Could not find artifact org.jboss.osgi.metadata:jbosgi-metadata:jar:3.0.1.Final in central (https://repo.maven.apache.org/maven2)

如果将它放在单个GitHub存储库中,它的使用也会更简单.

Also it will be simpler to play with it, if it would be located in single GitHub repository.

但是:

确保在所有被测模块中使用完全相同的JaCoCo版本.

Make sure that you use exact same version of JaCoCo in all modules under test.

并确保测试中的JVM正常终止,否则您可能会收到损坏的"jacoco.exec"文件,因为默认情况下会在JVM关闭期间将其保存.在JaCoCo的早期版本中,此类损坏的文件可能会导致

And make sure that JVM under test is terminated gracefully, otherwise you might receive corrupted "jacoco.exec" file, because by default it is saved during JVM shutdown. In earlier versions of JaCoCo such corrupted files might cause

IllegalStateException: Incompatible execution data for class...

(根据 https://github.com/jacoco/jacoco/issues/95#issuecomment-17271597 )

JaCoCo版本0.7.7中已改进了文件被截断的错误消息- https ://github.com/jacoco/jacoco/pull/397 最好使用最新发行的版本,因为它们带来了错误修复和改进- http://www.eclemma.org/jacoco/trunk/doc/changes.html

The error message in case of truncated files has been improved in JaCoCo version 0.7.7 - https://github.com/jacoco/jacoco/pull/397 And it is a good practice to use latest released versions as they bring bug-fixes and improvements - http://www.eclemma.org/jacoco/trunk/doc/changes.html

最后-看来您的测试完全位于与受测主代码不同的模块中. "report" mojo为当前模块的类创建报告.使用报告汇总"汇总各个模块的覆盖范围-其文档可在

Finally - seems that your tests located completely in a separate module from main code under test. "report" mojo creates report for classes of the current module. Use "report-aggregate" to aggregate coverage across modules - its documentation can be found at http://www.eclemma.org/jacoco/trunk/doc/report-aggregate-mojo.html Some examples were mentioned in https://groups.google.com/forum/#!msg/jacoco/8zjkSseaxD4/QOux-Ws-AgAJ

这篇关于Jacoco为现有耳朵运行时出现"IllegalStateException:类输入不兼容的执行数据…"的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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