简体   繁体   中英

Ant JUnit Error No runnable method. initializationError

We are getting this error, about which much has been written, from running JUnit via Ant. We double checked all the advice we saw in the previous questions about this error, and it seems that we got everything we need in our test class, a public no-arg constructor and a single method with the @Test annotation!

Testsuite: sim.V
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.016 sec

Testcase: initializationError took 0.002 sec
    Caused an ERROR
No runnable methods
java.lang.Exception: No runnable methods
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)


Testsuite: simvim

Here is our Ant build XML file:

<target name="junit" depends="build">
  <junit fork="no" printsummary="withOutAndErr">
     <test name="sim.V" outfile="TB" />
     <formatter usefile="true" type="plain"/>
     <classpath>
       <pathelement path="/afs/cad.njit.edu/u/j/g/jg284/libs/junit.jar"/>
       <pathelement path="/afs/cad.njit.edu/u/j/g/jg284/libs/hamcrest-core-1.3.jar"/>

        </classpath>
  </junit>
</target>

Here is our test class:

package sim;
import java.io.*;
import org.junit.*;
import static org.junit.Assert.*;

public class V {
  public V() {
  }

  @Test
  public void SG() throws IOException,sim.SE,Exception {
    Simulation S = new Simulation();
    S.logger = Simulate.createLogger("log.out","FINEST", false);
    S.stat = Simulate.createLogger("logstat.out","FINEST", false);
    sim.movers.SMover SM = new sim.movers.SMover(S);
    SM.TB();
  }
}

Try setting fork="yes" instead of fork="no" . I was able to reproduce your problem with fork="no" but not with fork="yes" .

I can't tell you why it doesn't work with fork="no" . I would guess at some kind of class-loading issue with Ant. I spent some time Googling but all I could find was a bug from 2006 (which I'm not sure is related as I don't have junit4.jar in ANT_HOME/lib ), and a blog post from last July, whose author mentions that:

Note: If you forget to set the fork attribute to true, you'll get an error message similar to the following:
(error message similar to yours omitted)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM