0

根据 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);
}
}
4

1 回答 1

3

您可以使用新的Robolectric 2.0 Config注释类型来绑定自定义 Shadow 类。

例如,您可以像这样注释测试方法:

@Config(shadows = { MyShadow.class, MyOtherShadow.class } ) public void testSomething { ... }

最好的问候, Seb

于 2013-08-09T06:28:31.300 回答