gpt4 book ai didi

java - Maven Java Surefire 无法创建测试类

转载 作者:行者123 更新时间:2023-12-03 11:20:25 26 4
gpt4 key购买 nike

我遇到了这个问题,当我运行 mvn test 时.这是输出的一部分:

Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] Unable to create test class 'com.models.ExampleTest'
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Unable to create test class 'com.ExampleTest'
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:657)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1161)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1002)

这是我的 pom.xml 的一部分:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

我已添加 <useSystemClassLoader>false</useSystemClassLoader>因为当 mvn test 命令给我时我遇到了问题 Could not find or load main class org.apache.maven.surefire.booter.ForkedBooter .所以我想我的 ClassLoader 有一些东西。我使用 Ubuntu 18.04、openjdk-11 和 maven 3.6.0。但是我尝试使用 oracle-jdk-11 和 openjdk-8 运行它。更重要的是,这个问题不依赖于一个项目。我用 maven 创建了一个空项目,并在那里添加了简单的类和简单的测试——结果是一样的。

最佳答案

正如日志所说:

Please refer to dump files (if any exist) [date].dump,[date]-jvmRun[N].dump and [date].dumpstream


您需要查看 xxx.dump文件。您应该可以在项目的 target 中找到它。目录。
在该文件中,您将找到导致

[ERROR] Unable to create test class 'com.models.ExampleTest'


此堆栈跟踪将与输出中的堆栈跟踪不同,它将帮助您确定错误的真正原因(在我的情况下它是 Javassist 版本,但它可能与您的情况无关)。
根据我的理解(我对 Surefire 一无所知),Surefire 充当容器并创建一个进程来运行测试。如果这个“内部”过程出现问题,它将被记录在转储文件中。但这不是 Surefire 的错(因为输出可能会让你想到)。

关于java - Maven Java Surefire 无法创建测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54761502/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com