我按照此处的教程从 Eclipse 执行测试运行程序: http://www.tutorialspoint.com/junit/junit_environment_setup.htm
尽管如此,当测试失败时,它会在控制台中输出,而不是在弹出窗口中输出,如下所示:
我可以更改下面的代码来获取该弹出窗口吗?
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(TestJunit.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
最佳答案
根据JUnit Wiki不支持可以从控制台运行的图形运行程序(旧版本的 JUnit 有一个,但可能不经常使用)。
但是有 Netbeans、Eclipse、IntelliJ 的集成运行程序。要在 IDE 中启动它们,请转到测试类,例如TestJunit
,右键单击,然后选择作为 JUnit Test 运行
(或类似选项)。
另一种方法是使用控制台运行程序输入 java org.junit.runner.JUnitCore TestJunit
关于java - 没有 Eclipse 的 JUnit : how to get the TestRunner Window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33577715/