There isn't a very clean way of doing this, since it isn't a common thing to do. You only need to print the output if you are creating a program that can be used to run tests on the command line, and JUnitCore itself does that.
All of the options involve using classes in an internal package.
Result r = JUnitCore.runMain(new RealSystem(), TestReader.class.getName())
If you want to print to something other than System.out
, you can create your own subclass of org.junit.internal.JUnitSystem
and use that instead of RealSystem
You can also use org.junit.internal.TextListener
. See runMain(JUnitSystem system, String... args)
in the JUnitCore source for an example.