我想从Java运行我的JUnit
测试。
我用:
JUnitCore runner = new JUnitCore();
runner.addListener(new TextListener(System.out));
runner.run(AdditionTest.class);
但我想要测试的名称,结果(true
或false
),失败
我是怎么做到的?
答案 0 :(得分:2)
阅读documentation!当您调用run(...)时,JUnitCore会返回Result个对象。结果对象包含getFailures()
,getRunTime()
以及wasSuccessful()
等方法。
JUnitCore runner = new JUnitCore();
runner.addListener(new TextListener(System.out));
Result result = runner.run(AdditionTest.class);
boolean wasSuccessful = result.wasSuccessful();
System.out.println("tests were successful: " + wasSuccessful);