Setting up Robolectric and Maven

I ran into some frustrations while trying to use Robolectric and the Android Maven Plugin.  The tests are not included in the same project as the main code, because Eclipse likes to bundle all the tests into the main apk when testing.  This causes its own nightmares and headaches.  So I separated the tests out into their own project.   When running the tests from the command line I was having NullPointer and ClassNotFound exceptions occurring.  Took a bit to find it, but the magic formula is the following configuration entry for your surefire-test-plugin:


Basically, Robolectric expects to be able to find resources in the same project as it is being run, unfortunately if you separate the tests out so they behave nicely with ADT, you have to point the working directory back to the root of your apps directory. Once I did this, all the tests started working.

This entry was posted in android, googletv, serenity. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s