Skip to content

Instantly share code, notes, and snippets.

@abombss
Created February 9, 2011 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abombss/817959 to your computer and use it in GitHub Desktop.
Save abombss/817959 to your computer and use it in GitHub Desktop.
Robolectric test runner with modifications for RoboGuice 1.2-SNAPSHOT
public class RobolectricGuicyTestRunner extends RobolectricTestRunner {
public RobolectricGuicyTestRunner(Class testClass) throws InitializationError {
super(testClass, new File("./application").exists() ? new File("./application") : new File("./"));
}
@Override
protected Application createApplication() {
Application app = super.createApplication();
Injector injector = RoboGuice.getInjector(Stage.PRODUCTION, app,new RoboModule(app), new RobolectricModule());
return app;
}
@Override
public void prepareTest(Object test) {
Injector injector = RoboGuice.getInjector(Robolectric.application);
injector.getInstance(ContextScope.class).enter(Robolectric.application);
injector.injectMembers(test);
}
static class RobolectricModule extends AbstractModule {
@Override
protected void configure() {
bind(Ln.BaseConfig.class).toInstance(new RobolectricLoggerConfig());
}
}
static class RobolectricLoggerConfig extends Ln.BaseConfig {
public RobolectricLoggerConfig() {
super();
this.packageName = "robo";
this.minimumLogLevel = Log.VERBOSE;
this.scope = "ROBO";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment