I am new to Android and its Instrumentation testing
I am having a boardcast receiver registered in my android manifest like
<receiver android:name=".phone.PhoneCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
and PhoneCallReceiver class is like below
public class PhoneCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
showAddCallLogScreen();
}
});
}
}`
I want to test whether Add call log pop up page displayed in the instrumentation test when call is ended , I tried to mock the call ended using below intent
My instrumentation test is like
@Test
public void testSystemCallLog(){
Intent intent = new Intent("android.intent.action.PHONE_STATE");
intent(TelephonyManager.EXTRA_INCOMING_NUMBER, wotkNumber);
intent(TelephonyManager.EXTRA_STATE, "IDLE");
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
I tried with this too InstrumentationRegistry.getInstrumentation().getContext().sendBroadcast(intent); too
But it also didn't work
Any idea how to mock a call in instrumentation test or how to test boardcast receivers in instrumentation test ?
or boardcast receivers can tested only in unit cases ?