Roboelectric 1.X の公式ガイド ( http://pivotal.github.io/robolectric/customizing.html ) に従って、独自のシャドウ クラスを使用する方法は、独自のテスト ランナーを作成し、適切なメソッドをオーバーライドすることです。 #Roboelectric.bindShadowClass を使用します (以下を参照)。
しかし、2.X では状況が変わっており、これを行う新しい方法を見つけることができないようです。カスタムシャドウクラスを変更せずに使用する方法を知っている人なら誰でも
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);
}
}