Reputation: 6808
As per the official guide for Roboelectric 1.X (at http://pivotal.github.io/robolectric/customizing.html), the way to use your own shadow class is to create your own test runner and override the appropriate method OR by using #Roboelectric.bindShadowClass (see below).
However, things have changed for 2.X and I can't seem to find the new way to do this. Anyone know how to use a custom shadow class without changing the
public class CustomTestRunner extends RobolectricTestRunner {
public CustomTestRunner(Class testClass) throws InitializationError {
super(testClass);
}
@Override public void beforeTest(Method method) {
Robolectric.bindShadowClass(ShadowBitmapFactory.class);
Robolectric.bindShadowClass(ShadowDrawable.class);
Robolectric.bindShadowClass(ShadowGeocoder.class);
}
}
Upvotes: 0
Views: 826
Reputation: 31
You can use the new Robolectric 2.0 Config annotation type to bind custom Shadow classes.
For example you annotate a test method like this:
@Config( shadows = { MyShadow.class, MyOtherShadow.class } ) public void testSomething { ... }
Best Regards, Seb
Upvotes: 3