I'm using Robolectric to test Android. I'm running my tests via maven, e.g.
mvn -Dtest=LogTest test
If I have code that writes to the logs, such as
Log.d("TAG", "blah");
or using Roboguice's Ln
Ln.d("blah");
I don't see any output in maven's surefire logs (text files).
Ideally, I actually want simple log statements to go to the console. I can write to the console by using System.out.println("blah")
, but of course I'd rather use the supported logging APIs.
So my question is, why am I not seeing log output at all, and how can I get the log messages written to the console?
I am running robolectric-2.0-alpha-3.
What worked for me was to set in the setUp method of my test the stream to stdout
Something like:
@Before
public void setUp() throws Exception {
ShadowLog.stream = System.out;
//you other setup here
}
With this version of robolectric I had no success doing the same (ShadowLog.stream = System.out
) in a custom TestRunner or in my TestLifeycleApplication.
Setting the system property System.setProperty("robolectric.logging","stdout");
was of no effect as well, but it might works in previous versions.