[英]Maven Java Surefire Unable to create test class
我在運行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 命令給我時我遇到了問題<useSystemClassLoader>false</useSystemClassLoader>
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 創建了一個空項目,並在那里添加了簡單的類和簡單的測試——結果是一樣的。
正如日志所說:
請參考轉儲文件(如果有的話)[date].dump、[date]-jvmRun[N].dump 和 [date].dumpstream
您需要查看xxx.dump
文件。 您應該可以在項目的target
目錄中找到它。 在該文件中,您將找到導致
[錯誤] 無法創建測試類“com.models.ExampleTest”
此堆棧跟蹤將與輸出中的堆棧跟蹤不同,它將幫助您確定錯誤的真正原因(在我的情況下它是 Javassist 版本,但它可能與您的情況無關)。
根據我的理解(我對 Surefire 一無所知),Surefire 充當容器並創建一個進程來運行測試。 如果這個“內部”過程出現問題,它將被記錄在轉儲文件中。 但這不是 Surefire 的錯(因為輸出可能會讓你想到)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.