4

我有一个 Maven 项目,使用“测试”阶段和“集成测试”阶段。在测试阶段,执行 JUnit-Tests,在集成测试中有 HTMLUnit-tests。我正在使用 Jacoco[1]-maven-plugin 来测量我的项目的 JUnit 测试完成的代码覆盖率。在进行集成测试时,我使用 maven-embedded-glassfish-plugin 启动 glassfish-server 并在执行测试之前部署我的应用程序。

可悲但真实,我必须暂时禁用 jacoco,因为它与“集成测试”阶段不协调。

Jacoco 的报告目标是/应该在准备包阶段执行,所以我认为它不应该影响集成测试阶段。但是当我启用 jacoco:report 时,由于内存大小问题 [2],我的集成测试不再运行。

如何停止 jacoco:report 影响集成测试阶段?


[1] http://www.eclemma.org/jacoco/

[2]

java.lang.instrument.IllegalClassFormatException: Error while instrumenting class com/steadystate/css/parser/SACParserCSS21TokenManager.
        at org.jacoco.agent.rt_6l8m50.CoverageTransformer.transform(CoverageTransformer.java:91)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:424)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        at com.steadystate.css.parser.SACParserCSS21.<init>(SACParserCSS21.java:2196)
        at com.steadystate.css.parser.SACParserCSS21.<init>(SACParserCSS21.java:23)
        at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.parseCSS(CSSStyleSheet.java:530)
        at com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet.<init>(CSSStyleSheet.java:152)
        at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLStyleElement.getSheet(HTMLStyleElement.java:73)
        at com.gargoylesoftware.htmlunit.javascript.host.css.StyleSheetList.item(StyleSheetList.java:129)
        at com.gargoylesoftware.htmlunit.javascript.host.Window.getComputedStyle(Window.java:1591)
        at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.getCurrentStyle(HTMLElement.java:2465)
        at com.gargoylesoftware.htmlunit.html.DomNode.isDisplayed(DomNode.java:688)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.isVisible(HtmlSerializer.java:377)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendText(HtmlSerializer.java:371)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:126)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendChildren(HtmlSerializer.java:249)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:198)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendChildren(HtmlSerializer.java:249)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:198)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendChildren(HtmlSerializer.java:249)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:198)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendChildren(HtmlSerializer.java:249)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.appendNode(HtmlSerializer.java:198)
        at com.gargoylesoftware.htmlunit.html.HtmlSerializer.asText(HtmlSerializer.java:57)
        at com.gargoylesoftware.htmlunit.html.DomNode.asText(DomNode.java:740)
        at webappTest.IndexIT.index(IndexIT.java:24)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)
Caused by: java.lang.RuntimeException: Method code too large!
        at org.jacoco.agent.rt_6l8m50.asm.MethodWriter.a(Unknown Source)
        at org.jacoco.agent.rt_6l8m50.asm.ClassWriter.toByteArray(Unknown Source)
        at org.jacoco.agent.rt_6l8m50.core.instr.Instrumenter.instrument(Instrumenter.java:70)
        at org.jacoco.agent.rt_6l8m50.core.instr.Instrumenter.instrument(Instrumenter.java:82)
        at org.jacoco.agent.rt_6l8m50.CoverageTransformer.transform(CoverageTransformer.java:89)
        ... 67 more
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.313 sec
Exception in thread "ThreadedStreamConsumer" Exception in thread "Thread-25" Exception in thread "Thread-26" Exception in thread "DynamicReloader"
4

1 回答 1

11

好的,所以我看到了问题。

类的方法 jjMoveNfa_0

http://grepcode.com/file/repo1.maven.org/maven2/net.sourceforge.cssparser/cssparser/0.9.5/com/steadystate/css/parser/SACParserCSS21TokenManager.java

4203 loc 非常长。因此,您的解决方案应该是避免对此类进行检测。

您可以通过告诉 jacoco-maven-plugin 来排除包含该类的包“com.steadystate”:

<plugin>
  <groupId>org.jacoco</groupId> 
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.version}</version>
  <configuration>
  <excludes>
    <exclude>**com.steadystate*</exclude>
  </excludes>
  ...
</plugin>
于 2013-01-28T13:58:58.043 回答