Is it possible to mock a system service on Android?

everything. I'm new to Mockito :)

Context mockContext = mock(Context.class); TelephonyManager mockTelephonyManager = mock(TelephonyManager.class); when(mockTelephonyManager.getNetworkCountryIso()).thenReturn("CN"); when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager); 

the above will not work if the espresso test tries to use telephony, it still returns the system network of the ISO country. Any thoughts? thanks!

+7
android mockito
source share
1 answer

It seems that anyone (Context.class) has solved my problem. When passing context as parameters. Not sure if the funny context will not work.

0
source share

All Articles