Reputation: 181
I would like running my JUnit
test from Java.
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
How I have it?
Upvotes: 0
Views: 318
Reputation: 31623
Read the documentation! JUnitCore returns a Result object when you call run(...). The result object has methods like getFailures()
, getRunTime()
and of course 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);
Upvotes: 2