How to print log messages to the output

1,295 views
Skip to first unread message

StKiller

unread,
Apr 18, 2012, 3:23:05 AM4/18/12
to robol...@googlegroups.com
Hi all,

In the tested code is used frequently Log.d method call for debugging. But when I run the tests, there is no output. I've found ShadowLog class, but I cannot understand how to use it. Please help.

StKiller

unread,
Apr 18, 2012, 3:58:52 AM4/18/12
to robol...@googlegroups.com
OK, I've found how to register ShadowLog and how to print it's messages. But anyway, it prints only invocations of Log.d that are called within test class. But how can I print Log.d messages invoked from app's code ?

Valtteri Virtanen

unread,
Apr 18, 2012, 4:00:08 AM4/18/12
to robol...@googlegroups.com
You can use Java's native System.out.println for example.

StKiller

unread,
Apr 18, 2012, 5:18:12 AM4/18/12
to robol...@googlegroups.com
Well, there was another issue - I used the ShadowActivity instead of real one, so the app's code wasn't invoked. Changing back to use of real class solved the issue : 

At the start of the test class : 


    static {
        ShadowLog.stream = System.out;
        Robolectric.bindShadowClass(ShadowLog.class);

Jan Berkel

unread,
Apr 18, 2012, 7:25:42 AM4/18/12
to robol...@googlegroups.com


On Wednesday, April 18, 2012 11:18:12 AM UTC+2, StKiller wrote:
Well, there was another issue - I used the ShadowActivity instead of real one, so the app's code wasn't invoked. Changing back to use of real class solved the issue : 

At the start of the test class : 


    static {
        ShadowLog.stream = System.out;
        Robolectric.bindShadowClass(ShadowLog.class);
    }



you can also set the system property "robolectric.logging" to one of

 * stdout  (logs to stdout)
 * stderr  (logs to stderr)
 * somefilename.txt  (logs to a file)
 
i added this a while ago but it isn't documented anywhere.

   jan


Reply all
Reply to author
Forward
Message has been deleted
0 new messages