On 07/10/2010, at 10:36 PM, Matthias Bohlen wrote:

> Hi,
> 
> this must be an FAQ but I have to ask it nevertheless because I failed to get 
> it right:
> 
> I have JUnit tests that run well inside Eclipse and fail inside gradle. Now, 
> I want to add System.out.println()-statements in the test case code so that I 
> can inspect variables when running under Gradle.
> 
> However, Gradle catches standard output and I am not able to see it.

The test's standard output end up in the test report. Could you add a JIRA 
issue if you want some way to see it on the console too?

If you want to add some output for debugging purposes, you could instead run 
the tests in debug mode:

gradle test -Dtest.debug

This will start the test in the debugger. You can then connect to the process 
from your IDE and inspect your tests in the debugger. You might find it useful 
to combine this with -Dtest.single to debug a single test:

gradle test -Dtest.debug -Dtest.single=MyBrokenTest

Have a look here for more information about the test task: 
http://www.gradle.org/0.9-rc-1/docs/userguide/java_plugin.html#sec:java_test

One (ugly) way to force some output be written to the console is to use the 
following instead of System.out:

PrintStream actualStdout = new PrintStream(new 
FileOutputStream(FileDescriptor.out))
actualStdout.println("hi from the tests.")

You could make actualStdout a static field somewhere.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to