我从Eclipse执行spring 3.2.8项目的此Junit(junit-4.4)没问题,(单击右键-> Run As-> Junit Test)
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
public class AccomodationTypeDaoTest extends BaseDaoTest {
private AccomodationTypeDao accTypeDao;
@Test
public void testFindAll() {
assertNotNull(accTypeDao.findAll());
}
@Autowired
public void setAccomodationTypeDao(AccomodationTypeDao daoInstance) {
this.accTypeDao = daoInstance;
}
}
@SuppressWarnings("deprecation")
public class BaseDaoTest extends AbstractAnnotationAwareTransactionalTests {
private static final String[] CONFIG_LOCATIONS = new String[] { "classpath:com/dao/testDataAccessContext.xml" };
@Override
protected String[] getConfigLocations() {
return CONFIG_LOCATIONS;
}
@Test
public void testBaseDaoTest() {
assertTrue(true);
}
}
我也没有问题,对包中的所有类都做同样的事情。
但是,当我单击测试文件夹/ MyProject / MyProjectWeb / test / src时,出现此异常:
java.lang.TypeNotPresentException: Type [unknown] not present
at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:75)
at com.sun.proxy.$Proxy6.value(Unknown Source)
at org.junit.internal.requests.ClassRequest.getRunnerClass(ClassRequest.java:49)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
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)
Caused by: java.lang.NoClassDefFoundError: org/junit/runners/BlockJUnit4ClassRunner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:390)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:371)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:300)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3217)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3224)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3224)
at java.lang.Class.getAnnotation(Class.java:3176)
at org.junit.internal.requests.ClassRequest.getRunnerClass(ClassRequest.java:45)
... 9 more
Caused by: java.lang.ClassNotFoundException: org.junit.runners.BlockJUnit4ClassRunner
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 37 more
最佳答案
在BlockJUnit4ClassRunner
的javadoc中:
/**
* [...]
* </ul>
*
* @since 4.5
*/
public class BlockJUnit4ClassRunner
因此它在4.4中不可用,您可能无需任何代码更改即可升级到4.11
关于java - java.lang.ClassNotFoundException:org.junit.runners.BlockJUnit4ClassRunner,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27361486/