2016-08-08 3 views
0

Android에서이 클래스를 테스트하여 실제로 전자 메일 보낸 사람 앱 선택기가 열리는 것을 확인하고 응용 프로그램을 선택하면 필드가 미리 채워지고 파일이 첨부됩니다.어떻게이 클래스를 Android에서 단위 테스트 할 수 있습니까?

UI를 통해 단위 테스트 또는 통합 테스트 또는 자동 테스트를 수행해야합니까? 설정 내가 필요로 할 어떻게 내가 분리 만이 클래스를 테스트 할 수 있습니다 어떤 종류의 : 당신은 Robolectric의 도움으로이 테스트 장치를 시도 할 수 있습니다

public class EmailSender { 

    public static void sendEmailWithAttachment(Context context, 
               String[] recipient, 
               String subject, 
               String attachmentFilePath) { 
     Intent emailIntent = new Intent(Intent.ACTION_SEND); 
     emailIntent .setType("vnd.android.cursor.dir/email"); 
     emailIntent .putExtra(Intent.EXTRA_EMAIL, recipient); 
     emailIntent .putExtra(Intent.EXTRA_STREAM, attachmentFilePath); 
     emailIntent .putExtra(Intent.EXTRA_SUBJECT, subject); 
     context.startActivity(Intent.createChooser(emailIntent , "Send email...")); 
    } 

} 
+1

참조 할 수 있지만 https://developer.android.com (당신이 UI 자동화와 같은 다른 도구를 사용한다고 생각합니다 /training/testing/ui-testing/uiautomator-testing.html) 또는 Robolectric과 같은 것에 대해서는 Neh가 썼습니다. – jeprubio

답변

1

. 당신이 방법 sendEmailWithAttachment를 호출 할 때 의도 이메일 전송 응용 프로그램을 시작하는 작업을 수행하는지 여부 , 당신은

ShadowActivity shadowActivity = shadowOf(activity); 
    Intent startedIntent = shadowActivity.getNextStartedActivity(); 
    ShadowIntent shadowIntent = shadowOf(startedIntent); 
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(targetActivityName)); 

은 또한 당신은 의도의 내용을 확인할 수 있습니다, 확인하실 수 있습니다. Robolectric을 사용하는 방법에 대한 자세한 내용은

당신은 당신은 안드로이드 - 에스프레소 태그로 질문을 표시 http://www.vogella.com/tutorials/Robolectric/article.html