java吧 关注:1,221,842贴子:12,674,947
  • 2回复贴,共1

请问测试类名以“Test”开头或结尾时mvn test报错怎么办?

只看楼主收藏回复

如题。只要有一个测试类名开头或结尾是“Test”就会报错。在其他电脑上曾经成功运行过在这台电脑上报错的代码。
环境是jdk1.8和maven3.8.6,如下图。尝试过更换jdk17,仍然会报错。

为还原该错误进行了测试,创建一个新maven项目,在测试文件夹中创建一个空的类“DemoTest”,运行mvn test,报错,如下图;将“DemoTest”重命名为“DemoTestt”,运行mvn test,通过。

完整报错信息如下
PS E:\code_work\java_work\idea_work\untitled> mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< org.example:untitled >------------------------
[INFO] Building untitled 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ untitled ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ untitled ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ untitled ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\code_work\java_work\idea_work\untitled\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ untitled ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to E:\code_work\java_work\idea_work\untitled\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ untitled ---
[INFO] Surefire report directory: E:\code_work\java_work\idea_work\untitled\target\surefire-reports
[WARNING] Invalid POM for org.apache.maven.surefire:surefire-junit3:jar:2.12.4, transitive dependencies (if any) will not be available, enable debug logging for more details
-------------------------------------------------------
T E S T S
-------------------------------------------------------
org.apache.maven.surefire.util.SurefireReflectionException: java.lang.ClassNotFoundException: org.apache.maven.surefire.junit.JUnit3Provider; nested exception is java.lang.ClassNotFoundException: org.apache.maven.surefire.junit.JUni
t3Provider
java.lang.ClassNotFoundException: org.apache.maven.surefire.junit.JUnit3Provider
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
at org.apache.maven.surefire.util.ReflectionUtils.loadClass(ReflectionUtils.java:228)
at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:128)
at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:239)
at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:122)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:81)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.541 s
[INFO] Finished at: 2022-07-18T10:04:32+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project untitled: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The fork
ed VM terminated without saying properly goodbye. VM crash or System.exit called ? -> [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/PluginExecutionException


IP属地:山东1楼2022-07-18 10:15回复
    这种情况都是清idea缓存


    IP属地:广东来自Android客户端2楼2022-07-18 11:51
    收起回复