0
如何在Android中測試此類以驗證它是否確實打開了電子郵件發件人應用程序選擇器,並且選擇了應用程序時,這些字段是預填充的並且文件已附加?如何在Android中對這個類進行單元測試?
是否應該通過UI進行單元測試或集成測試或自動化測試。 設置什麼樣的了,我需要,我怎麼能在單獨測試只有這個類:
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..."));
}
}
您與Android的咖啡標籤標示的問題,但我認爲你應該使用其他工具,如UI的Automator(https://developer.android.com /training/testing/ui-testing/uiautomator-testing.html)這樣的事情或Robolectric像Neh寫的 – jeprubio