[英]Run JUnit test from Java
I would like running my JUnit
test from Java. 我想从Java运行我的
JUnit
测试。
I use : 我用 :
JUnitCore runner = new JUnitCore();
runner.addListener(new TextListener(System.out));
runner.run(AdditionTest.class);
But I would like the name of the test, the result ( true
or false
), the failure 但我想要测试的名称,结果(
true
或false
),失败
How I have it? 我怎么了?
Read the documentation ! 阅读文档 ! JUnitCore returns a Result object when you call run(...).
调用run(...)时, JUnitCore返回一个Result对象。 The result object has methods like
getFailures()
, getRunTime()
and of course wasSuccessful()
. 结果对象有
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.