【发布时间】:2012-10-02 12:56:48
【问题描述】:
Robolectric 有一个名为ShadowMatrix 的影子类,但我不想使用它。如何将其从 robolectric 中移除?我希望改用原来的Matrix 类。
【问题讨论】:
标签: android testing shadow robolectric
Robolectric 有一个名为ShadowMatrix 的影子类,但我不想使用它。如何将其从 robolectric 中移除?我希望改用原来的Matrix 类。
【问题讨论】:
标签: android testing shadow robolectric
这行不通。在 android.jar 中只有类和方法的存根(没有主体的方法)。这就是您使用 Robolectric 在 Android 系统之外运行测试的原因。
你可以做的就是从github repository创建一个fork,改变ShadowMatrix的实现,构建并在你的项目中使用它。
【讨论】:
Matrix,它类似于android的矩阵,因为android.graphics.Matrix中有一些原生方法,我无法为它们提供适当的实现。
这对于Matrix 的具体问题可能无济于事,但我在一个测试中对另一类ShadowCountDownTimer 有类似的需求。我能够通过提供一个不会改变/添加CountDownTimer行为的替代阴影来绕过阴影:
// Shadow with no additional behavior
@Implements(CountDownTimer.class)
public static class DefaultCountDownTimer {
}
// Use this shadow just for this test
@Config(shadows = DefaultCountDownTimer.class)
@Test
public void testSomething() {
}
【讨论】: