爲了提高應用程序質量,我正在測試:單元測試和UI測試。因爲我在應用程序中使用Dropbox支持,所以我想測試它,並且我需要在測試前驗證Dropbox帳戶(在我的Android應用程序中,用戶可以保存文件,讀取它們,重命名等 - 基本文件例程)。如何使用Dropbox Java/Android SDK v2自動進行身份驗證?
的Dropbox提供Java/Android SDK v2用的例子,但即使command-line tool需要一些手動操作 - 打開的瀏覽器應用程序的URL,並選擇帳戶:
// Run through Dropbox API authorization process
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-authorize");
DbxWebAuth webAuth = new DbxWebAuth(requestConfig, appInfo);
DbxWebAuth.Request webAuthRequest = DbxWebAuth.newRequestBuilder()
.withNoRedirect()
.build();
String authorizeUrl = webAuth.authorize(webAuthRequest);
System.out.println("1. Go to " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first).");
System.out.println("3. Copy the authorization code.");
System.out.print("Enter the authorization code here: ");
String code = new BufferedReader(new InputStreamReader(System.in)).readLine();
if (code == null) {
System.exit(1); return;
}
code = code.trim();
DbxAuthFinish authFinish;
try {
authFinish = webAuth.finishFromCode(code);
} catch (DbxException ex) {
System.err.println("Error in DbxWebAuth.authorize: " + ex.getMessage());
System.exit(1); return;
}
System.out.println("Authorization complete.");
System.out.println("- User ID: " + authFinish.getUserId());
System.out.println("- Access Token: " + authFinish.getAccessToken());
任何可能性使Dropbox的身份驗證自動無需進行人工干預?我期望提供應用密鑰/祕密,帳戶電子郵件/密碼,並獲得會話accessToken
。
PS。我想避免使用Robelectric + Espresso並將其保留在單元/集成測試中,而不是在UI測試中。
是與應用程序包相關的訪問令牌嗎?我想知道爲我的產品應用程序接收的訪問令牌是否會被單元測試接受 – 4ntoine
Dropbox API訪問令牌僅標識應用程序用戶對。它不受限於特定的Java/Android包,因此您可以在多個位置/環境中使用相同的訪問令牌。 – Greg