Robolectric & android.util.Log

parityboy

Limp Gawd
Joined
Nov 13, 2010
Messages
390
I am currently building and maintaining a library of objects which runs on Android. The library is mostly pure Java; the only Android-specific code is android.util.Log, which is far more useful in an Android environment than System.out.println(). My build & test environment for this library is basically JDK 1.7, Ant, command line and a text editor. Using JUnit 4.11 for unit testing is fine apart from when it hits part of the library code which uses android.util.Log, at which point I get:


Code:
Exception in thread "main" java.lang.RuntimeException: Stub!


I've tried using the Robolectric "android-all-xxx" library, but I then get:

Code:
java.lang.UnsatisfiedLinkError: android.util.Log.println_native(IILjava/lang/String;Ljava/lang/String;)I
     [java]     at android.util.Log.println_native(Native Method)
     [java]     at android.util.Log.i(Log.java:160)

It would seem then that android.util.Log hasn't actually been implemented by Robolectric. Is this actually the case, or am I missing something? Do I have to use the Robolectric TestRunner or can I use the standard JUnit one?
 
I can't answer your question directly, but could SLF4J somehow be used here? I see there is a version for android (http://www.slf4j.org/android/). Maybe it would be possible to somehow use slf4j-android for your main project and use slf4j-jdk14 for your test code, for example.
 
Back
Top