I have a test class that I'm trying to run from a main method with the folowing code :
Result r = org.junit.runner.JUnitCore.runClasses(TestReader.class);
when I examine the Result object I can see that 5 tests have been run but nothing is printed on the screen.
Should I do something else to get an output ?
Yes, you should register TextListener
like this:
JUnitCore junit = new JUnitCore();
junit.addListener(new TextListener(System.out));
junit.run(TestReader.class);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With