android - Adding Test Module for RoboGuice When Using Robolectric 2 -


i upgrading robolectric version 1 2. in current version use following provide test module (for binding) roboguice.

public class robotestrunner extends robolectrictestrunner {      public robotestrunner(class<?> testclass) throws             initializationerror {         super(testclass);     }      @override     public void preparetest(object test) {         application app = robolectric.application;         roboguice.setbaseapplicationinjector(app, roboguice.default_stage,                 modules.override(roboguice.newdefaultrobomodule(app)).with(new                         testmodule()));         injector injector = roboguice.getinjector(app);         injector.injectmembers(test);     }  } 

however have upgraded preparetest method not in class. should run code in new version?

update

i have found way this. need create class extends android.app.application in project , reference in manifest. create class so

public class testapplication extends application implements testlifecycleapplication {      @override     public void oncreate() {         super.oncreate();          roboguice.setbaseapplicationinjector(this, roboguice.default_stage,                 roboguice.newdefaultrobomodule(this), new testmodule());     }      @override     public void beforetest(method method) {}      @override     public void preparetest(object test) {         testapplication application = (testapplication) robolectric.application;          roboguice.setbaseapplicationinjector(application, roboguice.default_stage,                 roboguice.newdefaultrobomodule(application), new testmodule());          roboguice.getinjector(application).injectmembers(test);     }      @override     public void aftertest(method method) {}  } 

as class has test @ start robolectric should automatically find , use it. doesn't seem happening. know why?

update 2

this blog suggest testmodule needs in same package have tests in different package. how work around this?

your testapplication class should extend own application class, not android.app.application, , should in same package application.

... have tests in different package.

that shouldn't problem. put testapplication in test module, use package application.

e.g., if you're using maven, files live here:

src/main/java/com/example/application.java src/test/java/com/example/testapplication.java


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -