BaseHostJUnit4測試
public abstract class BaseHostJUnit4Test
extends Object
implements IAbiReceiver , ITestInformationReceiver
java.lang.Object |
↳ | com.android.tradefed.testtype.junit4.BaseHostJUnit4Test |
用於執行主機 JUnit4 樣式測試的基底測試類別。此類別提供從主機端安裝、運行和清理儀器測試的支援。該類別是多設備相容的。應該是從主機端執行儀器測試的單一事實來源,以避免重複的實用程式和基底類別。
概括
公共方法 |
---|
final void | autoTearDown () 自動拆卸所有已安裝的 apk。 |
final IAbi | getAbi () |
final IBuildInfo | getBuild () |
final ITestDevice | getDevice () |
final IInvocationContext | getInvocationContext () |
final TestRunResult | getLastDeviceRunResults () 傳回最新運行的 runDeviceTests 產生的TestRunResult 。 |
final | getListDevices () |
TestInformation | getTestInformation () |
boolean | hasDeviceFeature (String feature) |
final void | installPackage ( DeviceTestRunOptions options) 根據裝置上的DeviceTestRunOptions 安裝apk。 |
final void | installPackage (String apkFileName, String... options) 在裝置上安裝指定名稱的 apk。 |
final void | installPackage ( ITestDevice device, String apkFileName, String... options) 在給定裝置上安裝指定名稱的 apk。 |
final void | installPackageAsUser ( ITestDevice device, String apkFileName, boolean grantPermission, int userId, String... options) 在給定裝置上為特定使用者安裝指定名稱的 apk。 |
final void | installPackageAsUser (String apkFileName, boolean grantPermission, int userId, String... options) 為特定使用者安裝指定名稱的 apk。 |
final boolean | isPackageInstalled (String pkg) 檢查設備上是否安裝了給定名稱的軟體包 |
final boolean | isPackageInstalled ( ITestDevice device, String pkg) 檢查設備上是否安裝了給定名稱的軟體包 |
final boolean | runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, instrumentationArgs, extraListeners) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName, Long testTimeoutMs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, instrumentationArgs) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, instrumentationArgs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests (String pkgName, String testClassName, String testMethodName) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( DeviceTestRunOptions options) 根據DeviceTestRunOptions 中的資訊運行偵測。 |
final boolean | runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, boolean isWindowAnimationDisabled, boolean isRestartDisabled, instrumentationArgs, extraListeners) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String pkgName, String testClassName, String testMethodName) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests (String pkgName, String testClassName, Integer userId, Long testTimeoutMs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests (String pkgName, String testClassName) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests (String pkgName, String testClassName, Long testTimeoutMs) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners) runDeviceTests ( ITestDevice device, String runner, String pkgName, String testClassName, String testMethodName, Integer userId, Long testTimeoutMs, Long maxTimeToOutputMs, Long maxInstrumentationTimeoutMs, boolean checkResults, boolean isHiddenApiCheckDisabled, boolean isTestApiCheckDisabled, boolean isIsolatedStorageDisabled, instrumentationArgs, extraListeners) 運行已安裝的檢測包的方法。 |
final boolean | runDeviceTests (String runner, String pkgName, String testClassName, String testMethodName) 運行已安裝的檢測包的方法。 |
final void | setAbi ( IAbi abi) |
final void | setTestInformation ( TestInformation testInformation) |
final String | uninstallPackage (String pkgName) 卸載設備上的軟體包。 |
final String | uninstallPackage ( ITestDevice device, String pkgName) 卸載裝置上的軟體包 |
公共構造函數
BaseHostJUnit4測試
public BaseHostJUnit4Test ()
公共方法
自動拆卸
public final void autoTearDown ()
自動拆卸所有已安裝的 apk。這將從安裝的裝置上卸載所有 apk。
獲取阿比
public final IAbi getAbi ()
取得設備列表
public final getListDevices ()
有設備功能
public boolean hasDeviceFeature (String feature)
安裝包
public final void installPackage (String apkFileName,
String... options)
在裝置上安裝指定名稱的 apk。 Apk 將會自動清理。
參數 |
---|
apkFileName | String : apk 檔的名稱。 |
options | String : 為安裝指令提供的額外選項 |
安裝包
public final void installPackage (ITestDevice device,
String apkFileName,
String... options)
在給定裝置上安裝指定名稱的 apk。 Apk 將會自動清理。
參數 |
---|
device | ITestDevice :要安裝 apk 的ITestDevice 。 |
apkFileName | String : apk 檔的名稱。 |
options | String : 為安裝指令提供的額外選項 |
以使用者身分安裝包
public final void installPackageAsUser (ITestDevice device,
String apkFileName,
boolean grantPermission,
int userId,
String... options)
在給定裝置上為特定使用者安裝指定名稱的 apk。
參數 |
---|
device | ITestDevice :要安裝 apk 的ITestDevice 。 |
apkFileName | String : apk 檔的名稱。 |
grantPermission | boolean : 安裝apk時是否傳遞授予權限標誌。 |
userId | int :安裝 apk 的使用者的使用者 ID。 |
options | String : 為安裝指令提供的額外選項 |
以使用者身分安裝包
public final void installPackageAsUser (String apkFileName,
boolean grantPermission,
int userId,
String... options)
為特定使用者安裝指定名稱的 apk。
參數 |
---|
apkFileName | String : apk 檔的名稱。 |
grantPermission | boolean : 安裝apk時是否傳遞授予權限標誌。 |
userId | int :安裝 apk 的使用者的使用者 ID。 |
options | String : 為安裝指令提供的額外選項 |
軟體包已安裝
public final boolean isPackageInstalled (String pkg)
檢查設備上是否安裝了給定名稱的軟體包
退貨 |
---|
boolean | 如果在裝置上找到該套件則為 true |
軟體包已安裝
public final boolean isPackageInstalled (ITestDevice device,
String pkg)
檢查設備上是否安裝了給定名稱的軟體包
參數 |
---|
device | ITestDevice :應卸載軟體套件的裝置。 |
pkg | String : 套件的名稱 |
退貨 |
---|
boolean | 如果在裝置上找到該套件則為 true |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String pkgName,
String testClassName,
String testMethodName,
Integer userId,
Long testTimeoutMs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String pkgName,
String testClassName,
String testMethodName,
Long testTimeoutMs,
Long maxTimeToOutputMs,
Long maxInstrumentationTimeoutMs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
maxTimeToOutputMs | Long :測試開始輸出內容的最大超時時間。 |
maxInstrumentationTimeoutMs | Long :完整檢測必須完成的最大超時。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String runner,
String pkgName,
String testClassName,
String testMethodName,
Integer userId,
Long testTimeoutMs,
Long maxTimeToOutputMs,
Long maxInstrumentationTimeoutMs,
boolean checkResults,
boolean isHiddenApiCheckDisabled,
boolean isTestApiCheckDisabled,
boolean isIsolatedStorageDisabled,
boolean isWindowAnimationDisabled,
instrumentationArgs,
extraListeners)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
runner | String |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
maxTimeToOutputMs | Long :測試開始輸出內容的最大超時時間。 |
maxInstrumentationTimeoutMs | Long :完整檢測必須完成的最大超時。 |
checkResults | boolean :是否檢查結果是否有當機。 |
isHiddenApiCheckDisabled | boolean :我們是否應該停用隱藏的 api 檢查。 |
isTestApiCheckDisabled | boolean :我們是否應該停用測試 api 檢查。 |
isIsolatedStorageDisabled | boolean :我們是否應該停用獨立儲存。 |
isWindowAnimationDisabled | boolean :我們是否應該停用視窗動畫。 |
instrumentationArgs | :傳遞給儀器的參數。 |
extraListeners | |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String pkgName,
String testClassName,
String testMethodName,
Long testTimeoutMs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String runner,
String pkgName,
String testClassName,
String testMethodName,
Integer userId,
Long testTimeoutMs,
Long maxTimeToOutputMs,
Long maxInstrumentationTimeoutMs,
boolean checkResults,
boolean isHiddenApiCheckDisabled,
instrumentationArgs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
runner | String |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
maxTimeToOutputMs | Long :測試開始輸出內容的最大超時時間。 |
maxInstrumentationTimeoutMs | Long :完整檢測必須完成的最大超時。 |
checkResults | boolean :是否檢查結果是否有當機。 |
isHiddenApiCheckDisabled | boolean :我們是否應該停用隱藏的 api 檢查。 |
instrumentationArgs | :傳遞給儀器的參數。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (String pkgName,
String testClassName,
String testMethodName)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String runner,
String pkgName,
String testClassName,
String testMethodName,
Integer userId,
Long testTimeoutMs,
Long maxTimeToOutputMs,
Long maxInstrumentationTimeoutMs,
boolean checkResults,
boolean isHiddenApiCheckDisabled,
boolean isTestApiCheckDisabled,
boolean isIsolatedStorageDisabled,
boolean isWindowAnimationDisabled,
boolean isRestartDisabled,
instrumentationArgs,
extraListeners)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
runner | String |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
maxTimeToOutputMs | Long :測試開始輸出內容的最大超時時間。 |
maxInstrumentationTimeoutMs | Long :完整檢測必須完成的最大超時。 |
checkResults | boolean :是否檢查結果是否有當機。 |
isHiddenApiCheckDisabled | boolean :我們是否應該停用隱藏的 api 檢查。 |
isTestApiCheckDisabled | boolean :我們是否應該停用測試 api 檢查。 |
isIsolatedStorageDisabled | boolean :我們是否應該停用獨立儲存。 |
isWindowAnimationDisabled | boolean :我們是否應該停用視窗動畫。 |
isRestartDisabled | boolean |
instrumentationArgs | :傳遞給儀器的參數。 |
extraListeners | |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String pkgName,
String testClassName,
String testMethodName)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (String pkgName,
String testClassName,
Integer userId,
Long testTimeoutMs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (String pkgName,
String testClassName)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (String pkgName,
String testClassName,
Long testTimeoutMs)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (ITestDevice device,
String runner,
String pkgName,
String testClassName,
String testMethodName,
Integer userId,
Long testTimeoutMs,
Long maxTimeToOutputMs,
Long maxInstrumentationTimeoutMs,
boolean checkResults,
boolean isHiddenApiCheckDisabled,
boolean isTestApiCheckDisabled,
boolean isIsolatedStorageDisabled,
instrumentationArgs,
extraListeners)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
device | ITestDevice :運作偵測的設備。 |
runner | String |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
userId | Integer :要執行測試的使用者的 ID。可以為空。 |
testTimeoutMs | Long :應用於每個測試案例的逾時(以毫秒為單位)。 |
maxTimeToOutputMs | Long :測試開始輸出內容的最大超時時間。 |
maxInstrumentationTimeoutMs | Long :完整檢測必須完成的最大超時。 |
checkResults | boolean :是否檢查結果是否有當機。 |
isHiddenApiCheckDisabled | boolean :我們是否應該停用隱藏的 api 檢查。 |
isTestApiCheckDisabled | boolean :我們是否應該停用測試 api 檢查。 |
isIsolatedStorageDisabled | boolean :我們是否應該停用獨立儲存。 |
instrumentationArgs | :傳遞給儀器的參數。 |
extraListeners | |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
運行設備測試
public final boolean runDeviceTests (String runner,
String pkgName,
String testClassName,
String testMethodName)
運行已安裝的檢測包的方法。之後立即使用getLastDeviceRunResults()
來取得結果的詳細資訊。
參數 |
---|
runner | String :要使用的偵測運行器。 |
pkgName | String :要運行的套件的名稱。 |
testClassName | String :要運行的測試類別的名稱。 |
testMethodName | String :要運行的類別中的測試方法的名稱。 |
退貨 |
---|
boolean | 如果成功且沒有失敗,則為真。否則為假。 |
設定阿比
public final void setAbi (IAbi abi)
public final void setTestInformation (TestInformation testInformation)
參數 |
---|
testInformation | TestInformation |
解除安裝包
public final String uninstallPackage (String pkgName)
卸載設備上的軟體包。
參數 |
---|
pkgName | String : 要卸載的 Android 套件 |
退貨 |
---|
String | 帶有錯誤代碼的String ,如果成功則為null |
解除安裝包
public final String uninstallPackage (ITestDevice device,
String pkgName)
卸載裝置上的軟體包
參數 |
---|
device | ITestDevice :應卸載軟體套件的裝置。 |
pkgName | String : 要卸載的 Android 套件 |
退貨 |
---|
String | 帶有錯誤代碼的String ,如果成功則為null |