Example of capturing log messages and local shadow binding

701 views
Skip to first unread message

Christian Williams

unread,
Nov 21, 2010, 7:27:04 PM11/21/10
to robol...@googlegroups.com
Thought this was maybe worth sharing:


Chester
chesterbr Chester 
@ 
@AntiXian666 well, since you asked :-) is there a way to make
Android Log calls (e.g.: http://bit.ly/cdZzlu) appear at stdout or a file?


For a single test, I set the shadow class of Log to be a class which does my bidding:

import android.util.Log;
import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.RobolectricTestRunner;
import com.xtremelabs.robolectric.util.Implements;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(RobolectricTestRunner.class)
public class LogTest {
    @Test
    public void testLogging() throws Exception {
        Robolectric.bindShadowClass(ShadowLog.class);

        Log.i("LogTest", "log message");
    }

    @Implements(Log.class)
    public static class ShadowLog {
        public static int i(java.lang.String tag, java.lang.String msg) {
            System.out.println("[" + tag + "] " + msg);
            return 0;
        }
    }
}
--Xian

Christopher Perry

unread,
Jan 22, 2013, 7:05:02 PM1/22/13
to robol...@googlegroups.com
This works for printing logs that occur in your test, but it doesn't print logs that occur in your test classes. No matter what I try to do I can't get logging to work.
Reply all
Reply to author
Forward
0 new messages