English 中文(简体)
外地 Error在试图对春天进行jUnit测试时
原标题:NoSuchFieldError when trying to run a jUnit test with Spring

到目前为止,我有两个测试点。 其中一种只使用jUnit框架,并作精细。 另一家图书馆使用春季测试图书馆,每当我尝试管理该图书馆时就设立这一例外。 任何可能引起问题的想法?

<><>>

java.lang.NoSuchFieldError: NULL
at org.junit.runners.ParentRunner.<init>(ParentRunner.java:48)
at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:59)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:104)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:27)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
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)

www.un.org/Depts/DGACM/index_spanish.htm Maven测试依附条件

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.7</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${org.springframework.version}</version>
    <scope>test</scope>
</dependency>

www.un.org/Depts/DGACM/index_spanish.htm 附属树

[INFO] [dependency:tree {execution: default-cli}]
[INFO] fake:war:1.0-SNAPSHOT
[INFO] +- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.springframework:spring-web:jar:3.0.5.RELEASE:compile
[INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] |  |  - org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] |  - org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] |     - commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- commons-codec:commons-codec:jar:1.4:compile
[INFO] +- org.glassfish:javax.faces:jar:2.1.3:compile
[INFO] +- org.richfaces.ui:richfaces-components-ui:jar:4.0.0.Final:compile
[INFO] |  +- org.richfaces.ui:richfaces-components-api:jar:4.0.0.Final:compile
[INFO] |  - org.richfaces.core:richfaces-core-api:jar:4.0.0.Final:compile
[INFO] +- org.richfaces.core:richfaces-core-impl:jar:4.0.0.Final:compile
[INFO] |  +- net.sourceforge.cssparser:cssparser:jar:0.9.5:compile
[INFO] |  |  - org.w3c.css:sac:jar:1.3:compile
[INFO] |  - com.google.guava:guava:jar:r08:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.2.0.Final:compile
[INFO] |  - org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO] +- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  - javax.activation:activation:jar:1.1:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.2.2:compile
[INFO] +- javax.servlet:jstl:jar:1.1.2:compile
[INFO] +- junit:junit:jar:4.7:test
[INFO] +- org.springframework:spring-test:jar:3.0.5.RELEASE:test
[INFO] +- javax.servlet:jsp-api:jar:2.0:provided
[INFO] - javax.servlet:servlet-api:jar:2.4:provided
最佳回答

你们是否使用旧的Eclipse(Galileo或之前)? 或更年版的吉尼特原始图? 如果是,这可能是问题的根源。 父母Runner正在寻找Sorter。 NUL,在Junnit 4.5介绍:

package org.junit.runner.manipulation;

public class Sorter implements Comparator<Description> {
    /**
     * NULL is a <code>Sorter</code> that leaves elements in an undefined order
     */
    public static Sorter NULL= new Sorter(new Comparator<Description>() {
        public int compare(Description o1, Description o2) {
            return 0;
        }});

如果你没有这种编号范围,你很可能采用4.5前版本。 在阁下的Eclipse, do Ctrl-Shift-T,看看看你是否有多种职业类别,如果是的话,他们都不会有4.5。 此外,看你在“建设道路”上建立的项目,如果是“日元”(不是“日元版”),将该项目删除,并再次尝试。

EDIT:这也可以由Maven的过境依赖造成。 或许你们的图书馆之一依靠的是54.5年之前的Junnit版本。

“Eclipse

问题回答

我已经解决这个问题,改为4.10。 最初的例外是:

java.lang.NoSuchFieldError: NULL
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:54)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:55)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.<init>(JUnit45AndHigherRunnerImpl.java:23)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.<init>(JUnit45AndHigherRunnerImpl.java:23)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.mockito.internal.runners.util.RunnerProvider.newInstance(RunnerProvider.java:39)
    at org.mockito.internal.runners.RunnerFactory.create(RunnerFactory.java:28)
    at org.mockito.runners.MockitoJUnitRunner.<init>(MockitoJUnitRunner.java:57)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:32)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:41)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:31)
    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)

这同你一样,是因为你在课堂上有多种日本人(不同版本)。 检查你这方面的班次(如果你重新放弃玉米依赖物:树),然后摆脱旧的班次(如果使用玉米,发现哪些直接进口的依赖进口产品转而进口旧的日元,并制作<代码><exclusion> on that Depend for the Japannit sub-dependency in You pom.xml)。 您也不妨更新您对最新版本(至少是4.10版)的实际依赖性。

我确实存在同样的问题,我发现这个问题是由来自org.jmock:jmock-junit4的过境依赖造成的。 当我用org.jmock:jmock取而代之时,就进行了分类。

我之所以出现这一错误,是因为同样的原因。 但是,在我的案件中,我无法看到朱利特的不同版本,仅仅看一看我的om子、xml或maven源树,因为我的项目正在使用中性附属物(项目间)。 i.e 项目“A”依赖“B”项目,因此项目“A”直接指“B”(工作空间)。 因此,如果发生这种情况,我们就无法确定在依赖中是否存在不同形式的陪审员。 因此,即结束“B”项目,将项目“A”从单页(而不是工作空间)删除。 在项目“A”源目录中,删除所有档案,但om、rc和v支持夹除外。 将该档案重新输入ec。 这个问题已经解决。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签