7
tất cả. Tôi mới sử dụng Mockito :)Có thể giả lập dịch vụ hệ thống trong Android
Context mockContext = mock(Context.class);
TelephonyManager mockTelephonyManager = mock(TelephonyManager.class);
when(mockTelephonyManager.getNetworkCountryIso()).thenReturn("CN");
when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager);
ở trên sẽ không hoạt động khi thử espresso cố gắng sử dụng điện thoại, nó vẫn trả về ISO của mạng hệ thống. bất kỳ suy nghĩ nào? cảm ơn!
bạn có thể dán mã được cập nhật của mình sau đó không? – Akshat