我目前能够运行JUnit测试程序做这样的事情:运行JUnit测试程序加载不同的.class文件
JUnitCore junit = new JUnitCore();
Result result = new Result();
File root = new File("rootWhereSommatoreTest.classIS");
URLClassLoader classLoader = URLClassLoader.newInstance(new URL[]{root.toURI().toURL() });
Class<?> cls = classLoader.loadClass("SommatoreTest");
result = junit.run(cls);
return result;
什么,我不喜欢这个代码是SommatoreTest.class必须在与Sommatore.class相同的目录工作。所以我想知道是否可以运行Junit测试,在同一个ClassLoader中从不同目录中单独加载.class文件,使SommatoreTest能够“看到”Sommatore。
在此先感谢您的答案!保持良好的工作!
只是想知道:你为什么要这样做?以如此复杂的方式加载JUnit测试有什么意义? – GhostCat
我必须创建一个应用程序,其中我在远程计算机上加载了一个TestClass,并且我的所有学生都必须编写一些代码,并且他们可以运行junit测试并发地向此远程计算机发送请求。 (对不起英语不好)如果不清楚就告诉我。感谢您的回答 –