示例中的 Jacoco 错误 - 空手道演示

问题描述 投票:0回答:1

我们正在扩大测试覆盖范围,并尝试实现自述文件中记录的对代码覆盖率的支持 - https://github.com/karatelabs/karate/tree/master/karate-demo#code-coverage-using-jacoco

当尝试在空手道演示中执行 Jacoco 的示例测试时,如所述 -

mvn clean test -Pcoverage
返回以下错误。 这个项目是最新的还是过时的?

错误:

karate-demo %  mvn clean test -Pcoverage
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< io.karatelabs:karate-demo >----------------------
[INFO] Building karate-demo 1.5.0
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] 1 problem was encountered while building the effective model for org.javassist:javassist:jar:3.20.0-GA during dependency collection step for project (use -X to see details)
[INFO] 
[INFO] --- clean:3.2.0:clean (default-clean) @ karate-demo ---
[INFO] Deleting /Users/xxx/karate/karate-demo/target
[INFO] 
[INFO] --- jacoco:0.7.9:prepare-agent (default-prepare-agent) @ karate-demo ---
[INFO] argLine set to -javaagent:/Users/xxx/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/xxx/karate/karate-demo/target/jacoco.exec
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ karate-demo ---
[INFO] Copying 6 resources from src/main/resources to target/classes
[INFO] 
[INFO] --- compiler:3.13.0:compile (default-compile) @ karate-demo ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 33 source files with javac [debug target 17] to target/classes
[INFO] /Users/xxx/karate/karate-demo/src/main/java/com/intuit/karate/demo/controller/WebSocketHandler.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/xxx/karate/karate-demo/src/main/java/com/intuit/karate/demo/controller/WebSocketHandler.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- resources:3.3.1:testResources (default-testResources) @ karate-demo ---
[INFO] Copying 151 resources from src/test/java to target/test-classes
[INFO] 
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ karate-demo ---
[INFO] Recompiling the module because of changed dependency.
[INFO] Compiling 51 source files with javac [debug target 17] to target/test-classes
[INFO] /Users/xxx/karate/karate-demo/src/test/java/demo/DemoTestSelected.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/xxx/karate/karate-demo/src/test/java/demo/DemoTestSelected.java: Recompile with -Xlint:unchecked for details.
[INFO] 
[INFO] --- surefire:3.2.5:test (default-test) @ karate-demo ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:569)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:491)
        at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:503)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
        at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
        at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
        at org.jacoco.agent.rt.internal_8ff85ea.PreMain.createRuntime(PreMain.java:55)
        at org.jacoco.agent.rt.internal_8ff85ea.PreMain.premain(PreMain.java:47)
        ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
        at java.base/java.lang.Class.getField(Class.java:2117)
        at org.jacoco.agent.rt.internal_8ff85ea.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
        ... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message Outstanding error when calling method in invokeJavaAgentMainMethod at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 619
*** java.lang.instrument ASSERTION FAILED ***: "success" with message invokeJavaAgentMainMethod failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 459
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 422
/bin/sh: line 1: 48527 Abort trap: 6           '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java' '-Dfile.encoding=UTF-8' '-javaagent:/Users/xxx/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/xxx/karate/karate-demo/target/jacoco.exec' '-jar' '/Users/xxx/karate/karate-demo/target/surefire/surefirebooter-20241217135432930_3.jar' '/Users/xxx/karate/karate-demo/target/surefire' '2024-12-17T13-54-32_873-jvmRun1' 'surefire-20241217135432930_1tmp' 'surefire_0-20241217135432930_2tmp'
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[WARNING] Corrupted channel by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file /Users/xxx/karate/karate-demo/target/surefire-reports/2024-12-17T13-54-32_873-jvmRun1.dumpstream
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.925 s
[INFO] Finished at: 2024-12-17T13:54:33-07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.2.5:test (default-test) on project karate-demo: 
[ERROR] 
[ERROR] Please refer to /Users/xxx/karate/karate-demo/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd '/Users/xxx/karate/karate-demo' && '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java' '-Dfile.encoding=UTF-8' '-javaagent:/Users/xxx/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/xxx/karate/karate-demo/target/jacoco.exec' '-jar' '/Users/xxx/karate/karate-demo/target/surefire/surefirebooter-20241217135432930_3.jar' '/Users/xxx/karate/karate-demo/target/surefire' '2024-12-17T13-54-32_873-jvmRun1' 'surefire-20241217135432930_1tmp' 'surefire_0-20241217135432930_2tmp'
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 134
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd '/Users/xxx/karate/karate-demo' && '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java' '-Dfile.encoding=UTF-8' '-javaagent:/Users/xxx/.m2/repository/org/jacoco/org.jacoco.agent/0.7.9/org.jacoco.agent-0.7.9-runtime.jar=destfile=/Users/xxx/karate/karate-demo/target/jacoco.exec' '-jar' '/Users/xxx/karate/karate-demo/target/surefire/surefirebooter-20241217135432930_3.jar' '/Users/xxx/karate/karate-demo/target/surefire' '2024-12-17T13-54-32_873-jvmRun1' 'surefire-20241217135432930_1tmp' 'surefire_0-20241217135432930_2tmp'
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 134
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:643)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285)
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1241)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1090)
[ERROR]         at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:910)
[ERROR]         at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
[ERROR]         at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
[ERROR]         at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
[ERROR]         at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
[ERROR]         at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
[ERROR]         at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
[ERROR]         at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
[ERROR]         at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
[ERROR]         at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
[ERROR]         at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR]         at java.base/java.lang.reflect.Method.invoke(Method.java:569)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
[ERROR]         at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

结果位于 target/sunfire-reports 文件夹中

# Created at 2024-12-17T13:54:33.211
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed'.

# Created at 2024-12-17T13:54:33.212
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)'.

# Created at 2024-12-17T13:54:33.212
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'V  [libjvm.dylib+0x4dd8a4]  jni_FatalError+0x10c'.

# Created at 2024-12-17T13:54:33.213
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'V  [libjvm.dylib+0x649c40]  JvmtiExport::post_vm_initialized()+0x284'.

# Created at 2024-12-17T13:54:33.213
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'V  [libjvm.dylib+0x9b60b0]  Threads::create_vm(JavaVMInitArgs*, bool*)+0x864'.

# Created at 2024-12-17T13:54:33.213
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'V  [libjvm.dylib+0x4fa9e8]  JNI_CreateJavaVM+0x78'.

# Created at 2024-12-17T13:54:33.214
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'C  [libjli.dylib+0xac08]  JavaMain+0x104'.

# Created at 2024-12-17T13:54:33.214
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'C  [libjli.dylib+0xda74]  ThreadJavaMain+0xc'.

# Created at 2024-12-17T13:54:33.327
Corrupted channel by directly writing to native stream in forked JVM 1. Stream 'C  [libsystem_pthread.dylib+0x72e4]  _pthread_start+0x88'.
karate jacoco
1个回答
0
投票

根据

/bin/sh:第 1 行:48527 中止陷阱:6 '/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home/bin/java'

您使用的是 Java 版本 17

并根据

[信息] --- jacoco:0.7.9:prepare-agent (default-prepare-agent) @ karate-demo ---

您使用的是 JaCoCo 版本 0.7.9,该版本已有 7 年历史,不支持 Java 17。

JaCoCo 版本 0.8.8 中添加了对 Java 17 的支持,今天发布的最新版本是 0.8.12 - 请参阅 https://www.jacoco.org/jacoco/trunk/doc/changes.html

© www.soinside.com 2019 - 2024. All rights reserved.