2012-02-07 5 views
2

장치의 기본 메일 클라이언트를 시작하는 활동에 대한 JUnit 테스트를 작성하고 있습니다. "보내기"활동이 시작되었는지 확인한 후 "보내기"버튼에 클릭 이벤트를 보냅니다.ActivityMonitor 인 텐트 필터 ACTION_SENDTO가 맞지 않습니다.

"보내기"활동에 대한 참조를 얻기 위해 인 텐트 필터가있는 ActivityMonitor를 설정했습니다. 테스트를 실행하는 동안 메일 보내기 활동이 표시되지만 불행히도 모니터가 절대로 안타깝다는 것을 알 수 있습니다. 여기

찾을 시도 단위 테스트 코드 활동 "보내기"

// register activity monitor for the send mail activity 
Instrumentation instrumentation = getInstrumentation(); 
IntentFilter filter = new IntentFilter(Intent.ACTION_SENDTO); 
ActivityMonitor monitor = instrumentation.addMonitor(filter, null, false); 

// click on the "Send Feedback" button (use Robotium here) 
solo.clickOnButton(0); 

// wait for the send mail activity to start 
Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, 5000); 
assertNotNull(currentActivity); 

을 그리고 여기에 활동이 응용 프로그램에서 시작됩니다 "로 보내기"방법입니다

Uri uri = Uri.parse("mailto:[email protected]"); 
Intent i = new Intent(Intent.ACTION_SENDTO, uri);         
i.putExtra(Intent.EXTRA_SUBJECT, "Message Title");   
i.putExtra(Intent.EXTRA_TEXT, "Hello"); 
startActivity(i); 

의도 필터가 잘못 설정 되었습니까? 또는 프로젝트에서 정의되지 않은 활동을 모니터링하는 것이 불가능합니까?

도움 주셔서 감사합니다.

+0

나는 "진짜"활동이 시작되지 않았기 때문에 문제의 의도를 파악할 수 없다고 생각합니다. 사실 의도를 시작한 후 활동중인 활동의 목록이 비어 있습니다. 하지만이 문제를 해결할 수 있었습니까? – Shilaghae

+0

불행히도 없습니다. 나는 결코 그 문제를 해결하지 못했다. – Georges

답변

0

나는 내 테스트에서이 문제를 겪었고 이것이 나를 위해 일했습니다.

이 시점에서 테스트는 정상적으로 작동하지만 모니터가 예상 할 데이터를 알지 못하므로 의도 필터가 아무 것도 잡아 내지 못합니다.

// register activity monitor for the send mail activity  
Instrumentation instrumentation = getInstrumentation();  
IntentFilter filter = new IntentFilter(Intent.ACTION_SENDTO); 


//Here you just need to say to your intent filter what exactly to look for 
filter.addDataType(CommonDataKinds.Email.CONTENT_TYPE); 



ActivityMonitor monitor = instrumentation.addMonitor(filter, null, true); 
// click on the "Send Feedback" button (use Robotium here) 
solo.clickOnButton(0);  
// wait for the send mail activity to start 
Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, 5000); 
assertNotNull(currentActivity); 

당신이 SMS를 보내기 위해이 작업을 수행 할 경우, 그 라인은 다음과 같습니다

filter.addDataScheme(Constants.SCHEME_SMS); 
2

내가이이 문제를 가지고하고 Robotium의 솔로가 설치 때문에 액티비티 모니터가 작동하지 않는 것으로 나타났다는 자신의 모니터. 이 모니터는 모든 의도를 포착하므로 사용자 정의 모니터는 호출되지 않습니다.

나는 결국 솔로 모니터를 제거하고 내 자신을 삽입 한 다음 솔로 모니터를 다시 추가하여 모니터를 먼저 일치시킵니다. ((메일 응용 프로그램) 다른 활동을 시작할 때, 당신은 테스트 환경의 자제력을 잃게 때문에 차단 모니터를 만드는 것이 유용 할 것입니다 : 보조 노트로

// register activity monitor for the send mail activity 
Instrumentation instrumentation = getInstrumentation(); 
IntentFilter filter = new IntentFilter(Intent.ACTION_SENDTO); 
ActivityMonitor monitor = new ActivityMonitor(filter, null, false); 
ActivityMonitor soloMonitor = solo.getActivityMonitor(); 

// Remove the solo monitor, so your monitor is first on the list. 
instrumentation.removeMonitor(soloMonitor); 
// add your own monitor. 
instrumentation.addMonitor(monitor); 
// Re-add the solo monitor 
instrumentation.addMonitor(soloMonitor); 

// click on the "Send Feedback" button (use Robotium here) 
solo.clickOnButton(0); 

// wait for the send mail activity to start 
Activity currentActivity = instrumentation.waitForMonitorWithTimeout(monitor, 5000); 
assertNotNull(currentActivity); 

: 코드는 다음과 같이 보일 것입니다 ie new ActivityMonitor(filter, null, true);)

관련 문제