嗨,每次我收到此异常跟踪与Robolectric定制阴影工作Robolectric自定义阴影代码
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at org.robolectric.bytecode.RobolectricInternals.newInstanceOf(RobolectricInternals.java:33)
at org.robolectric.Robolectric.newInstanceOf(Robolectric.java:345)
at org.robolectric.shadows.ShadowBitmapFactory.create(ShadowBitmapFactory.java:120)
at org.robolectric.shadows.ShadowBitmapFactory.decodeFile(ShadowBitmapFactory.java:72)
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java)
什么我做的是我有一个自定义阴影
@Implements(Bitmap.class)
class MyShadowBitmap extends org.robolectric.shadows.ShadowBitmap {
public MyShadowBitmap() {
// can also be some other config value
setConfig(Bitmap.Config.ARGB_8888);
}
}
一会儿,我使用这个类
public class CustomTestRunner extends RobolectricTestRunner {
public CustomTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}
@Override
public Setup createSetup() {
return new MySetup();
}
@Override
protected ShadowMap createShadowMap() {
return super.createShadowMap()
.newBuilder()
.addShadowClass(MyShadowBitmap.class)
.build();
}
}
}
而且我运行我的测试案例
@Test
@Config(shadows = {
MyShadowBitmap.class
})
请帮助我,我做错了,如何使用robolectric中的自定义阴影!
你解决了吗?如果是这样,请选择一个答案。 –