如何创建可以从每个java测试中调用的泛型函数?在我的函数startappli中,我有:
public class startappli{
public void testMain (String[] args)
{
String[] logInfos = new String[3];
logInfos[0] = (String) args[0];
logInfos[1] = (String) args[1];
}
@BeforeClass
public static void setupOnce() {
final Thread thread = new Thread() {
public void run() {
entrypointtoGUI.main(new String[]{"arg0 ", "arg1"});
}
};
try {
thread.start();
} catch (Exception ex) {
}
}
}在toto.java中,我按如下方式调用函数: startappli.testmain(loginfo) --它不起作用吗?
我的函数: Runner.java包含: public class RunAppli {
@BeforeClass公共静态void setupOnce() { final线程=新线程(){ public void (){
Main.main(new String[]{"-rtebase ", "C:\\bin"});
}
};
try {
thread.start();
} catch (Exception ex) {
}
}@Test public void test() {
URL path = this.getClass().getResource("../Tester/map.xml");
System.out.println("Cover: " + cmapURL);
}
}}
在我的java测试TestDemo.java中,我调用了启动appli : RunAppli .setupOnce()的StartAppli;我获得了到xml文件的路径: RunAppli .path,我们应该在函数中使用@Test吗?有暗示吗?谢谢
发布于 2010-03-03 12:49:35
我假设您的问题是没有执行startappli.setupOnce()。
我认为这是因为startappli不包含@Test方法,因此JUnit不把它作为测试类。因此,@BeforeClass被省略,该函数不由JUnit执行。
解决方案可以是在这个类中放置一个@Test方法。或者,如果希望在每个Java测试方法之前调用它,则应该从每个测试类中的@Before方法中显式调用它(如果希望每个测试类只运行一次,则从@BeforeClass方法调用它)。
注意: startappli不是Java类的好名称,因为按照惯例,类名应该是camel大小写,例如StartAppli。
发布于 2010-03-03 12:49:51
你做了很多错误的事情(实际上-全部)
testmain()和main(),而方法是camelCased - testMain()。@Test注释的方法。我建议在开始之前阅读JUnit手册。
https://stackoverflow.com/questions/2371054
复制相似问题