我的类需要一个位图,但mockito的模拟上下文对象似乎无法做到这一点:
public class PlayerTest {
@Mock // Mocking the android context class
Context mMockContext;
// intantiating object from that mocked class
Context mContext;
private Player player;
private Bitmap playerBitmap;
private int screenX;
private int screenY;
@Before
public void setupPlayer(){
playerBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.player);
player = new Player(mContext, screenX, screenY,playerBitmap);
}
...
答案 0 :(得分:4)
您是否只能使用private Bitmap playerBitmap
注释@Mock
?
我无法看到课程的其余部分,但我认为您正在使用Mockito JUnit跑步者。如果没有,您需要使用它,或者在设置方法中拨打MockitoAnnotations.initMocks(this)
。