Ant JUnit错误没有runnable方法。 initializationError

问题描述 投票:0回答:1

通过Ant运行JUnit,我们得到了这个错误,关于编写了多少。我们仔细检查了我们在前面关于这个错误的问题中看到的所有建议,似乎我们在测试类中得到了我们需要的一切,一个公共的无参数构造函数和一个带有@Test注释的单个方法!

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

这是我们的Ant构建XML文件:

<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>

这是我们的测试类:

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();
  }
}
java ant junit junit4
1个回答
0
投票

尝试设置fork="yes"而不是fork="no"。我能够用fork="no"重现你的问题但不能用fork="yes"重现你的问题。

我无法告诉你为什么它与fork="no"不兼容。我猜想Ant的某种类加载问题。我花了一些时间谷歌搜索,但我能找到的只是a bug from 2006(我不确定是否相关,因为我在junit4.jar没有ANT_HOME/lib),以及来自去年7月的blog post,其作者提到:

注意:如果您忘记将fork属性设置为true,则会收到类似于以下内容的错误消息: (与您的错误消息类似)

© www.soinside.com 2019 - 2024. All rights reserved.