1

我是 Android 及其仪器测试的新手

我在我的 android 清单中注册了一个广播接收器,例如

<receiver android:name=".phone.PhoneCallReceiver">
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
    </receiver>

和 PhoneCallReceiver 类如下

    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();
        }
            });
           
         }
       
     }`

我想测试通话结束时是否在仪表测试中显示添加通话日志弹出页面,我尝试使用以下意图模拟通话结束

我的仪器测试就像

    @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);
}

我也尝试过 InstrumentationRegistry.getInstrumentation().getContext().sendBroadcast(intent); 也

但它也没有工作

知道如何在仪器测试中模拟呼叫或如何在仪器测试中测试广播接收器吗?

还是广播接收器只能在单元情况下进行测试?

4

0 回答 0