在我的Java EE 7项目中,我正在使用Arquillian 1.1.11.Final和一个托管的Glassfish容器进行测试。由于我想检查代码覆盖率,我想整合JaCoCo。我尝试使用Arquillian JaCoCo扩展并按如下方式配置它:
...
<properties>
<version.jacoco>0.7.9</version.jacoco>
<version.arquillian_jacoco>1.0.0.Alpha9</version.arquillian_jacoco>
</properties>
...
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-jacoco</artifactId>
<version>${version.arquillian_jacoco}</version>
</dependency>
...
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco}</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<includes>*com/my/package/MyClassTest.java</includes>
</configuration>
</execution>
</executions>
</plugin>
...
运行mvn test
会导致错误(方法代码太大!)。
...
[INFO] --- jacoco-maven-plugin:0.7.9:prepare-agent (default) @ test ---
[INFO] argLine set to -javaagent:C:\\Users\\stewe\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.9\\org.jacoco.agent-0.7.9-runtime.jar=destfile=C:\\Development\\projects\\project\\test\\target\\jacoco.exec,includes=*com/my/package/MyClassTest.java
...
Starting container using command: [java, -jar, c:\Development\payara41\glassfish\modules\admin-cli.jar, start-domain, --verbose, --debug, -t]
Aug 30, 2017 11:18:38 AM com.sun.enterprise.admin.launcher.GFLauncherLogger info
INFORMATION: JVM invocation command line:
C:\Program Files\Java\jdk1.8.0_131\bin\java.exe
// does not list the JaCoCo agent
...
Aug 30, 2017 11:18:59 AM org.jboss.arquillian.container.glassfish.clientutils.GlassFishClientUtil getResponseMap
SCHWERWIEGEND: [status: SERVER_ERROR reason: Internal Server Error]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 43.124 s <<< FAILURE! - in com.itac.smartdata.client.jobmanager.JobLoggingTest
[ERROR] com.itac.smartdata.client.jobmanager.JobLoggingTest Time elapsed: 43.108 s <<< ERROR!
javax.ws.rs.ProcessingException: Failed to write asset to output: /lib/drools-compiler.jar
Caused by: org.jboss.shrinkwrap.api.exporter.ArchiveExportException: Failed to write asset to output: /lib/drools-compiler.jar
Caused by: org.jboss.shrinkwrap.api.exporter.ArchiveExportException: Failed to write asset to output: /org/drools/compiler/lang/DRL5Lexer.class
Caused by: java.lang.RuntimeException: Could not instrument Asset ByteArrayAsset [content size=114584bytes]
Caused by: java.io.IOException: Error while instrumenting class arquillian.
Caused by: java.lang.RuntimeException: Method code too large!
....
但是,它没有Arquillian JaCoCo扩展,并且将JaCoCo代理直接附加到domain.xml中的托管Glassfish:
<jvm-options>-javaagent:C:\Development\jacocoagent.jar=destfile=C:\Development\test-coverage.exec,append=true,includes=com.my.package.*</jvm-options>
问题:我错过了一些配置吗?我包含的类只包含简短的方法,并使用直接附件。为什么Arquillian扩展会失败?