Pivotal Labs developers have given this presentation several times.
@RunWith(RobolectricTestRunner.class)at the top of your test class.
The jerk lawyers at Google won’t allow the Google maps add-on library stubs to be uploaded to Maven Central. You need to manually install them yourself.
Make sure you’ve got Android SDK 16 or later downloaded, then do this:
cd $ANDROID_HOME ls -1d add-ons/addon-google_apis-google-* | sort | tail -1 | xargs -I% mvn install:install-file -DgroupId=com.google.android.maps -DartifactId=maps -Dversion=16_r3 -Dpackaging=jar -Dfile=%/libs/maps.jar
NOTE: this problem no longer happens in Robolectric 2.0. You oughta upgrade!
Robolectric cannot find your Android SDK. You can tell Robolectric how to find your SDK root in several ways:
sdk.dir in a
local.properties file by running the following in your project’s root dir:
$ android update project -p .
Setting up a
local.properties file is a solution that will work for most IDEs since you don’t need to worry about getting environment variables passed around.
ANDROID_HOME environment variable. You can put this in your
.bash_profile for example. You may need to do some extra work to get your IDE to pick it up.
Set the Java system property
android.sdk.path, e.g. by putting
-Dandroid.sdk.path=/path/to/android/sdk on the command line.
As a last resort, Robolectric will try running
which android to find the executable on your path. Add the SDK tools to your path: