我想監視如果startService(...)呼叫正處於活動取得:Service Intent - 它會被ActivityMonitor捕獲嗎?
public void testShouldCallServiceOnSendButtonPress() throws Exception {
assertNotNull(activity.pictureToSend);
ActivityMonitor androidMock = help.mockIntent(1);
TouchUtils.clickView(this, activity.sendButton);
help.assertBehavior(androidMock);
}
public ActivityMonitor mockIntent(int numberOfExpectedIntentsSentToAndroid) {
this.numberOfExpectedIntentsSentToAndroid = numberOfExpectedIntentsSentToAndroid;
IntentFilter intentFilter = null;
return androidMock = instrumentation.addMonitor(intentFilter, null, true);// catch all
}
上面我加入一個包羅萬象的監視器(應該抓住這兩個活動和服務意圖,對不對? !)
assertNotNull(this.startService(new Intent(this, MyService.class)));
上面我驗證服務是否已成功啓動,並且是。
可是......包羅萬象的顯示器從不打,instrumentation.checkMonitorHit()不是> = 1
任何想法,爲什麼?
是否有可能代碼嘲笑你? ;)儘管如此,你是否嘗試過監視特定的活動?如果您遇到了更普遍的問題,或者這是一個簡單的錯誤修正,這可能會給您一個想法。 – Codeman
它嘲笑我所有的時間:),是的,當測試意向MediaStore.ActionImageCapture beeing拋出,監視器工作,所以... 問題轉述:ActivityMonitors應該爲服務以及活動,工作,對嗎? – user77115