出现junit 出错,找不到文件,可以这么解决。

  • Post author:
  • Post category:其他



myeclipse工程 junit不能运行 ClassNotFoundException

来自:http://www.cnblogs.com/java-zone/articles/2730722.html

错误提示:

1
2
3
4
5
6
7
8
9
10
11
12
13

java.lang.ClassNotFoundException: com.huawei.adapter.XXXXXTest



at java.net.URLClassLoader$


1


.run(URLClassLoader.java:


200


)



at java.security.AccessController.doPrivileged(Native Method)



at java.net.URLClassLoader.findClass(URLClassLoader.java:


188


)



at java.lang.ClassLoader.loadClass(ClassLoader.java:


307


)



at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:


301


)



at java.lang.ClassLoader.loadClass(ClassLoader.java:


252


)



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


)

原因在于maven生成class的目录被改变,需要重新设置output目录

解决办法一:

打开工程的.classpath文件:

1
2
3
4
5
6
7

<?xml version=


"1.0"


encoding=


"UTF-8"


?>

<classpath>



<classpathentry kind=


"src"


path=


"src/main/java"


/>



<classpathentry kind=


"src"


path=


"src/main/config"


/>



<classpathentry kind=


"src"


path=


"src/test/java"


/>



.......

</classpath

将output=”target/test-classes”加上就好用了

1
2
3
4
5

<?xml version=


"1.0"


encoding=


"UTF-8"


?>

<classpath>



<classpathentry kind=


"src"


path=


"src/main/java"


/>



<classpathentry kind=


"src"


path=


"src/main/config"


/>



<classpathentry kind=


"src"


output=


"target/test-classes"


path=


"src/test/java"


/>

解决办法二:

1.打开项目,右击进入Properties>>JAva Build Path

2.勾选下方Allow  output folders for source folders

3.设置上方的output folder路径