我的类需要一个位图,但 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);
}
...
最佳答案
你不能用@Mock
注解private Bitmap playerBitmap
吗?
我看不到类(class)的其余部分,但我推测您正在使用 Mockito JUnit 运行器。如果没有,您需要使用它,或者在您的设置方法中调用 MockitoAnnotations.initMocks(this)
。
关于java - 如何使用 mockito 获取位图资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46270341/