user2998243
user2998243

Reputation: 181

Run JUnit test from Java

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

Answers (1)

Thomas Uhrig
Thomas Uhrig

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

Related Questions