我为我的 android 应用程序编写测试,我需要从我的类中模拟一个方法,该方法在我测试的方法中调用。这是我的课:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
.....
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (!isAppOnForeground(this)) {
DoSomeThing();
}
}
}
public boolean isAppOnForeground(Context context) {
return isAppOnForeground;
}
}
我想在返回真假onMessageReceived时测试方法。isAppOnForeground
我试试
@Test
public void onMessageReceived() {
MyFirebaseMessagingService mockMyFirebaseMessagingService = org.mockito.Mockito.mock(MyFirebaseMessagingService.class);
when(mockMyFirebaseMessagingService.isAppOnForeground(any(Context.class))).thenReturn(false);
mockMyFirebaseMessagingService.onMessageReceived(remoteMessage);
...
}
但是当我运行这个测试时,我没有看到方法调用onMessageReceived(断点不起作用)。我怎样才能嘲笑isAppOnForeground和打电话onMessageReceived?
饮歌长啸
相关分类