BaseHostJUnit4Test

public abstract class BaseHostJUnit4Test
extends Object implements IAbiReceiver, ITestInformationReceiver

java.lang.Object
   ↳ com.android.tradefed.testtype.junit4.BaseHostJUnit4Test


用於執行主機 JUnit4 樣式測試的基礎測試類別。這個類別支援從主機端安裝、執行及清理檢測設備測試。這堂課與多種裝置相容。 應做為從主機端執行檢測設備測試的單一可靠資料來源,以避免重複的公用程式和基礎類別。

摘要

公用建構函式

BaseHostJUnit4Test()

公用方法

final void autoTearDown()

自動拆解所有已安裝的 APK。

final IAbi getAbi()
final IBuildInfo getBuild()
final ITestDevice getDevice()
final IInvocationContext getInvocationContext()
final TestRunResult getLastDeviceRunResults()

傳回最近執行的 runDeviceTests 產生的 TestRunResult

final List<ITestDevice> 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 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, boolean instrumentInPcc, Map<String, String> instrumentationArgs, List<ITestLifeCycleReceiver> extraListeners)

執行已安裝檢測設備套件的方法。

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, Map<String, String> instrumentationArgs, List<ITestLifeCycleReceiver> extraListeners)

執行已安裝檢測設備套件的方法。

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, Map<String, String> instrumentationArgs)

執行已安裝檢測設備套件的方法。

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 pkgName, String testClassName, String testMethodName, Long testTimeoutMs)

執行已安裝檢測設備套件的方法。

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, Map<String, String> instrumentationArgs, List<ITestLifeCycleReceiver> 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(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)

解除安裝裝置上的套件

公用建構函式

BaseHostJUnit4Test

public BaseHostJUnit4Test ()

公用方法

autoTearDown

public final void autoTearDown ()

系統會自動拆解所有已安裝的 APK。這會從安裝 APK 的裝置解除安裝所有 APK。

擲回
DeviceNotAvailableException

getAbi

public final IAbi getAbi ()

傳回
IAbi

getBuild

public final IBuildInfo getBuild ()

傳回
IBuildInfo

getDevice

public final ITestDevice getDevice ()

傳回
ITestDevice

getInvocationContext

public final IInvocationContext getInvocationContext ()

傳回
IInvocationContext

getLastDeviceRunResults

public final TestRunResult getLastDeviceRunResults ()

傳回最近一次執行 runDeviceTests 時產生的 TestRunResult。如果沒有結果,則為空值。

傳回
TestRunResult

getListDevices

public final List<ITestDevice> getListDevices ()

傳回
List<ITestDevice>

getTestInformation

public TestInformation getTestInformation ()

傳回
TestInformation

hasDeviceFeature

public boolean hasDeviceFeature (String feature)

參數
feature String

傳回
boolean

擲回
DeviceNotAvailableException

installPackage

public final void installPackage (DeviceTestRunOptions options)

根據裝置上的 DeviceTestRunOptions 安裝 APK。系統會自動清除 APK。

參數
options DeviceTestRunOptions:套件安裝選項。

擲回
DeviceNotAvailableException
TargetSetupError

installPackage

public final void installPackage (String apkFileName, 
                String... options)

在裝置上安裝指定名稱的 APK。系統會自動清除 APK。

參數
apkFileName String:APK 檔案的名稱。

options String:提供給安裝指令的額外選項

擲回
DeviceNotAvailableException
TargetSetupError

installPackage

public final void installPackage (ITestDevice device, 
                String apkFileName, 
                String... options)

在指定裝置上安裝指定名稱的 APK。系統會自動清除 APK。

參數
device ITestDevice:要安裝 APK 的 ITestDevice

apkFileName String:APK 檔案的名稱。

options String:提供給安裝指令的額外選項

擲回
DeviceNotAvailableException
TargetSetupError

installPackageAsUser

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:提供給安裝指令的額外選項

擲回
DeviceNotAvailableException
TargetSetupError

installPackageAsUser

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:提供給安裝指令的額外選項

擲回
DeviceNotAvailableException
TargetSetupError

isPackageInstalled

public final boolean isPackageInstalled (String pkg)

檢查裝置上是否已安裝指定名稱的套件

參數
pkg String:套件名稱

傳回
boolean 如果裝置上找到套件,則為 true

擲回
DeviceNotAvailableException

isPackageInstalled

public final boolean isPackageInstalled (ITestDevice device, 
                String pkg)

檢查裝置上是否已安裝指定名稱的套件

參數
device ITestDevice:應解除安裝套件的裝置。

pkg String:套件名稱

傳回
boolean 如果裝置上找到套件,則為 true

擲回
DeviceNotAvailableException

runDeviceTests

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, 
                boolean instrumentInPcc, 
                Map<String, String> instrumentationArgs, 
                List<ITestLifeCycleReceiver> 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

instrumentInPcc boolean

instrumentationArgs Map:要傳遞至檢測的引數。

extraListeners List

傳回
boolean 如果成功且未發生失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

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, 
                Map<String, String> instrumentationArgs, 
                List<ITestLifeCycleReceiver> 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 Map:要傳遞至檢測的引數。

extraListeners List

傳回
boolean 如果成功且未發生失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

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, 
                Map<String, String> 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 Map:要傳遞至檢測的引數。

傳回
boolean 如果成功且未發生失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

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 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

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 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

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 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                String testMethodName)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

testMethodName String:要執行的類別中測試方法的名稱。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (DeviceTestRunOptions options)

根據 DeviceTestRunOptions 中的資訊執行插樁作業。

參數
options DeviceTestRunOptionsDeviceTestRunOptions,負責檢測設定。

傳回
boolean 如果成功且未發生失敗,則為 True。否則傳回「false」。

擲回
com.android.tradefed.device.DeviceNotAvailableException
DeviceNotAvailableException

runDeviceTests

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, 
                Map<String, String> instrumentationArgs, 
                List<ITestLifeCycleReceiver> 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 Map:要傳遞至檢測的引數。

extraListeners List

傳回
boolean 如果成功且未發生失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (ITestDevice device, 
                String pkgName, 
                String testClassName, 
                String testMethodName)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
device ITestDevice:要執行檢測的裝置。

pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

testMethodName String:要執行的類別中測試方法的名稱。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                Integer userId, 
                Long testTimeoutMs)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

userId Integer:要對其執行測試的使用者 ID,可為空值。

testTimeoutMs Long:套用至每個測試案例的逾時時間 (以毫秒為單位)。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (String pkgName, 
                String testClassName)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (String pkgName, 
                String testClassName, 
                Long testTimeoutMs)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

testTimeoutMs Long:套用至每個測試案例的逾時時間 (以毫秒為單位)。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

runDeviceTests

public final boolean runDeviceTests (String runner, 
                String pkgName, 
                String testClassName, 
                String testMethodName)

執行已安裝檢測設備套件的方法。請在之後立即使用 getLastDeviceRunResults() 取得結果詳細資料。

參數
runner String:要使用的檢測執行器。

pkgName String:要執行的套件名稱。

testClassName String:要執行的測試類別名稱。

testMethodName String:要執行的類別中測試方法的名稱。

傳回
boolean 如果成功且沒有失敗,則為 True。否則傳回「false」。

擲回
DeviceNotAvailableException

setAbi

public final void setAbi (IAbi abi)

參數
abi IAbi

setTestInformation

public final void setTestInformation (TestInformation testInformation)

參數
testInformation TestInformation

uninstallPackage

public final String uninstallPackage (String pkgName)

解除安裝裝置上的套件。

參數
pkgName String:要解除安裝的 Android 套件

傳回
String 含有錯誤代碼的 String,或成功時的 null

擲回
DeviceNotAvailableException

uninstallPackage

public final String uninstallPackage (ITestDevice device, 
                String pkgName)

解除安裝裝置上的套件

參數
device ITestDevice:應解除安裝套件的裝置。

pkgName String:要解除安裝的 Android 套件

傳回
String 含有錯誤代碼的 String,或成功時的 null

擲回
DeviceNotAvailableException