Maven项目中mvn clean后找不到測试类问题

时间:2022-12-13 14:39:39

在Maven项目中进行单元測试,但mvn clean后又一次mvn install项目,再次进行单元測试。会有下面的错误。

<span style="font-family:KaiTi_GB2312;font-size:18px;">Class not found com.core.order.service.impl.OrderServiceImplTest
java.lang.ClassNotFoundException: com.core.order.service.impl.OrderServiceImplTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
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 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)</span>

主要是由于mvn install时,默认会排除打包測试类,导致project中的測试类 没有编译成.class文件,所以才会报上述错误。

因此。能够通过


eclipse->project->clean


又一次编译下,再次执行单元測试就能够成功了。