NoSuchFieldError when trying to run a jUnit test with Spring

Are you using an older version of Eclipse (Galileo or before)? or an older version of the junit plugin? If so, this may be the cause of the problem. ParentRunner is looking for Sorter.NULL, which was introduced in JUnit 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;
        }});

If you don’t have this bit of code, you’re probably using a pre-4.5 version. On your Eclipse, do Ctrl-Shift-T and see if you have multiple versions of the Sorter class available, and if so, make sure neither of them are pre 4.5. Also, look in your project setup in your Build Path, and if there is JUnit entry (not the maven version), remove it, and try again.

EDIT: This can also be caused by a transitive dependency of Maven. Maybe one of your libraries has a dependency on a JUnit version which is pre-4.5.

Eclipse Build Path, JUnit entry

Leave a Comment