Process crashes during creation of RoboGuice injector, if there is a mocked instance in any module

Unfortunately, if there’s an issue with the setup steps for RoboGuice & unit testing, you can get this sort of error. No magic short answer, but rather a set of steps to follow exactly.

BTW, you’re using RoboGuice 1.1 – AbstractAndroidModule & RoboUnitTest no longer exist in RoboGuice 2.0. RoboGuice 1.1 is deprecated, so best overall solution is to move to newest version according to these instructions Upgrading to 2.0.

However, just in case you’re attached to RoboGuice 1.1, here’s some steps to follow:

  • Don’t have inconsistent generated code/build files after refactoring/changing package names etc. Delete generated code, do a Clean & Build, even recreate a new project and copy source files in.
  • Have your app code in one project (RoboGuice dependent, Instrumentation/RoboUnitTestCase/AndroidMock independent). You app code project has within lib: guice-2.0-no_aop.jar and roboguice-1.1.2.jar.
  • Have your unit test code in another project that references it (RoboGuice independent, Instrumentation/RoboUnitTestCase/AndroidMock independent). Instructions here Before You Get Started. Your test code project has within lib: AndroidMockGenerator.jar.
  • In your app project, your App + Module classes look something like this:

    package com.mypackage;
    import android.content.Context;
    public class MyApplication extends roboguice.application.RoboApplication {
    static MyModule myModule;    
    // this constructor usually called by app
    public MyApplication(Context context) {
    // This constructor called by unit tests.  This is unfortunately small amount of 
    // 'abstraction leakage' of unit test needs into app code.
    public MyApplication(Instrumentation instrumentation) {
    public static void setModule(MyModule module) {
        MyApplication.myModule = module;
    public static MyModule getModule() {
        return MyApplication.myModule;


    package com.mypackage;
    public class MyModule extends roboguice.config.AbstractAndroidModule {
    // this will be injected
    protected UsefulObject myUsefulInstance;    
    public void setUsefulObject(UsefulObject usefulInstance) {
        this.myUsefulInstance = usefulInstance;
    public UsefulObject getUsefulObject() {
        return this.myUsefulInstance;
    protected void configure() {


  • In your test project, your test case class looks something like this:

    import android.test.suitebuilder.annotation.LargeTest;    
    import com.mypackage.MyApplication;    
    import com.mypackage.MyModule;    
    import com.mypackage.UsefulObject;    
     //import com.mypackage.UsefulObjectSimpleImplementation;    
    import android.test.suitebuilder.annotation.MediumTest;    
    import android.test.suitebuilder.annotation.SmallTest;    
    import roboguice.test.RoboUnitTestCase;
    public class TestMyModule extends RoboUnitTestCase<MyApplication> {
    protected void setUp() throws Exception {
        UsefulObject instance = // new UsefulObjectSimpleImplementation(); 
        MyModule mockModule = new MyModule();
    // Make sure you use one of the @*Test annotations AND begin
    // your testcase's name with "test"
    public void test01() {


  • Ensure that for the test project, the AndroidManifest.xml file has the following entry:

   <instrumentation android:name="android.test.InstrumentationTestRunner"
     android:label="Tests for com.mypackage"/>
  • Before running your test, ensure your emulator is started and is running healthily, by running a different, simple “Hello World” app first. When this succeeds, then run your app. Lastly, run your test project.

Should work after this. Best of luck & let me know!

Leave a Comment