HostTest
public
class
HostTest
extends Object
implements
IAbiReceiver,
IBuildReceiver,
IConfigurationReceiver,
IDeviceTest,
IDiscoverTestClasses,
IRemoteTest,
IRuntimeHintProvider,
IShardableTest,
ITestAnnotationFilterReceiver,
ITestCollector,
ITestFilterReceiver
| java.lang.Object | |
| ↳ | com.android.tradefed.testtype.HostTest |
適用於 JUnit 主機測試的測試執行器。如果要執行的測試實作 IDeviceTest,這個執行器會傳遞裝置的參照。
摘要
常數 | |
|---|---|
String |
SET_OPTION_DESC
|
String |
SET_OPTION_NAME
|
公用建構函式 | |
|---|---|
HostTest()
|
|
公用方法 | |
|---|---|
void
|
addAllExcludeAnnotation(Set<String> notAnnotations)
新增註解的 |
void
|
addAllExcludeFilters(Set<String> filters)
新增要排除的測試篩選器 |
void
|
addAllIncludeAnnotation(Set<String> annotations)
新增註解 |
void
|
addAllIncludeFilters(Set<String> filters)
新增要納入測試的篩選器 |
void
|
addExcludeAnnotation(String notAnnotation)
如果測試標示了註解,則會新增註解來排除測試。 |
void
|
addExcludeFilter(String filter)
新增要排除的測試篩選器。 |
void
|
addIncludeAnnotation(String annotation)
新增註解,以便在測試標記時加入。 |
void
|
addIncludeFilter(String filter)
新增要納入的測試篩選器。 |
void
|
clearExcludeAnnotations()
刪除目前追蹤的所有排除註解。 |
void
|
clearExcludeFilters()
刪除目前追蹤的所有排除篩選器。 |
void
|
clearIncludeAnnotations()
刪除目前追蹤的所有 include 註解。 |
void
|
clearIncludeFilters()
刪除目前追蹤的所有納入篩選器。 |
int
|
countTestCases()
傳回測試中所有類別的測試案例數量 |
IAbi
|
getAbi()
|
Set<String>
|
getClassNames()
|
ITestDevice
|
getDevice()
取得受測裝置。 |
Set<String>
|
getExcludeAnnotations()
傳回要排除的註解目前 |
Set<String>
|
getExcludeFilters()
傳回排除篩選器的目前 |
Set<String>
|
getIncludeAnnotations()
傳回要納入的註解目前 |
Set<String>
|
getIncludeFilters()
傳回包含篩選器的目前 |
long
|
getRuntimeHint()
以毫秒為單位傳回測試的預期執行時間。 |
void
|
run(TestInformation testInfo, ITestInvocationListener listener)
Runs the tests, and reports result to the listener. |
void
|
setAbi(IAbi abi)
|
void
|
setBuild(IBuildInfo buildInfo)
|
void
|
setCollectTestsOnly(boolean shouldCollectTest)
啟用或停用測試收集模式 |
void
|
setConfiguration(IConfiguration configuration)
注入使用的 |
void
|
setDevice(ITestDevice device)
注入受測裝置。 |
static
void
|
setOptionToLoadedObject(Object testObj, List<String> keyValueOptions)
裝置執行器可使用這個輔助程式,以與 HostTest 相同的方式 (從 set-option) 設定選項。 |
void
|
setTestInformation(TestInformation testInfo)
|
Collection<IRemoteTest>
|
split(Integer shardCount, TestInformation testInfo)
我們會依測試類別或方法,將測試結果依個人分開。 |
受保護的方法 | |
|---|---|
HostTest
|
createHostTest(Class<?> classObj)
在分片時建立 HostTest 執行個體的輔助程式。 |
IBuildInfo
|
getBuild()
取得 HostTest 收到的建構資訊。 |
ClassLoader
|
getClassLoader()
傳回預設類別載入器。 |
final
List<Class<?>>
|
getClasses()
|
File
|
getJarFile(String jarName, TestInformation testInfo)
檢查不同用途的構件通常所在的位置,找出 JAR 檔。 |
boolean
|
hasJUnit4Annotation(Class<?> classObj)
Helper to determine if we are dealing with a Test class with Junit4 annotations. |
Object
|
loadObject(Class<?> classObj)
載入類別物件並設定測試資訊 (裝置、建構)。 |
void
|
setClassName(String className)
清除並設定要執行的類別名稱。 |
void
|
setMethodName(String methodName)
設定要執行的函式名稱。 |
boolean
|
shouldTestRun(AnnotatedElement annotatedElement)
檢查具有註解的元素是否通過篩選條件。 |
常數
SET_OPTION_DESC
public static final String SET_OPTION_DESC
常數值:
「要傳遞至受測類別的選項,鍵和值應以半形冒號『:』分隔;舉例來說,如果受測類別支援指令列中的『--iteration 1』,則應傳遞為『--set-option iteration:1』或『--set-option iteration:key=value』,以便將選項傳遞至對應。如要逸出含有「:」或「=」的值,請使用反斜線。如要指定特定類別,請指定該類別。「--set-option
SET_OPTION_NAME
public static final String SET_OPTION_NAME
常數值: "set-option"
公用建構函式
HostTest
public HostTest ()
公用方法
addAllExcludeAnnotation
public void addAllExcludeAnnotation (Set<String> notAnnotations)
新增註解的 Set,如果測試標示了註解,就會排除這些註解。
| 參數 | |
|---|---|
notAnnotations |
Set |
addAllExcludeFilters
public void addAllExcludeFilters (Set<String> filters)
新增要排除的測試篩選器 Set。
| 參數 | |
|---|---|
filters |
Set |
addAllIncludeAnnotation
public void addAllIncludeAnnotation (Set<String> annotations)
新增 Set 註解,以便在測試標記時納入。
| 參數 | |
|---|---|
annotations |
Set |
addAllIncludeFilters
public void addAllIncludeFilters (Set<String> filters)
新增要納入測試的篩選器Set。
| 參數 | |
|---|---|
filters |
Set |
addExcludeAnnotation
public void addExcludeAnnotation (String notAnnotation)
如果測試標示了註解,則新增註解以排除測試。
| 參數 | |
|---|---|
notAnnotation |
String |
addExcludeFilter
public void addExcludeFilter (String filter)
新增要排除的測試篩選器。
| 參數 | |
|---|---|
filter |
String |
addIncludeAnnotation
public void addIncludeAnnotation (String annotation)
新增註解,以便在測試標記時加入。
| 參數 | |
|---|---|
annotation |
String |
addIncludeFilter
public void addIncludeFilter (String filter)
新增要納入的測試篩選條件。
| 參數 | |
|---|---|
filter |
String |
clearExcludeAnnotations
public void clearExcludeAnnotations ()
刪除目前追蹤的所有排除註解。
clearExcludeFilters
public void clearExcludeFilters ()
刪除目前追蹤的所有排除篩選器。
clearIncludeAnnotations
public void clearIncludeAnnotations ()
刪除目前追蹤的所有 include 註解。
clearIncludeFilters
public void clearIncludeFilters ()
刪除目前追蹤的所有包含篩選器。
countTestCases
public int countTestCases ()
傳回測試中所有類別的測試案例數量
| 傳回 | |
|---|---|
int |
|
getClassNames
public Set<String> getClassNames ()
| 傳回 | |
|---|---|
Set<String> |
|
getRuntimeHint
public long getRuntimeHint ()
以毫秒為單位傳回測試的預期執行時間。這段時間用於平衡分片執行作業的負載
| 傳回 | |
|---|---|
long |
|
得分
public void run (TestInformation testInfo, ITestInvocationListener listener)
執行測試,並向接聽程式回報結果。
| 參數 | |
|---|---|
testInfo |
TestInformation:包含執行測試實用資訊的 TestInformation 物件。 |
listener |
ITestInvocationListener:測試結果的 ITestInvocationListener |
| 擲回 | |
|---|---|
DeviceNotAvailableException |
|
setCollectTestsOnly
public void setCollectTestsOnly (boolean shouldCollectTest)
啟用或停用測試收集模式
setConfiguration
public void setConfiguration (IConfiguration configuration)
注入使用的 IConfiguration。
| 參數 | |
|---|---|
configuration |
IConfiguration |
setOptionToLoadedObject
public static void setOptionToLoadedObject (Object testObj,
List<String> keyValueOptions)裝置執行器可使用這個輔助程式,透過 set-option 設定選項,方式與 HostTest 相同。
| 參數 | |
|---|---|
testObj |
Object:將接收選項的物件。 |
keyValueOptions |
List:選項清單,格式為 HostTest set-option 所需。 |
setTestInformation
public void setTestInformation (TestInformation testInfo)
| 參數 | |
|---|---|
testInfo |
TestInformation |
拆分
public Collection<IRemoteTest> split (Integer shardCount, TestInformation testInfo)
我們會依測試類別或方法,將測試結果分給個別使用者。
| 參數 | |
|---|---|
shardCount |
Integer:嘗試的分片數量。 |
testInfo |
TestInformation:父項 TestInformation |
| 傳回 | |
|---|---|
Collection<IRemoteTest> |
要個別執行的子測試集合,或 null 如果測試目前無法分片 |
受保護的方法
createHostTest
protected HostTest createHostTest (Class<?> classObj)
在分片時建立 HostTest 執行個體的輔助程式。覆寫以從 HostTest 傳回任何子項。
| 參數 | |
|---|---|
classObj |
Class |
| 傳回 | |
|---|---|
HostTest |
|
getClassLoader
protected ClassLoader getClassLoader ()
傳回預設類別載入器。
| 傳回 | |
|---|---|
ClassLoader |
|
getClasses
protected final List<Class<?>> getClasses ()
| 傳回 | |
|---|---|
List<Class<?>> |
|
| 擲回 | |
|---|---|
IllegalArgumentException |
|
getJarFile
protected File getJarFile (String jarName,
TestInformation testInfo)檢查不同用途的構件通常所在的位置,找出 JAR 檔案。
| 參數 | |
|---|---|
jarName |
String |
testInfo |
TestInformation |
| 傳回 | |
|---|---|
File |
|
| 擲回 | |
|---|---|
FileNotFoundException |
|
hasJUnit4Annotation
protected boolean hasJUnit4Annotation (Class<?> classObj)
Helper,用於判斷我們是否正在處理具有 Junit4 註解的 Test 類別。
| 參數 | |
|---|---|
classObj |
Class |
| 傳回 | |
|---|---|
boolean |
|
loadObject
protected Object loadObject (Class<?> classObj)
載入類別物件並設定測試資訊 (裝置、建構)。
| 參數 | |
|---|---|
classObj |
Class |
| 傳回 | |
|---|---|
Object |
|
setClassName
protected void setClassName (String className)
清除並設定要執行的類別名稱。
| 參數 | |
|---|---|
className |
String |
setMethodName
protected void setMethodName (String methodName)
設定要執行的函式名稱。
這項功能可用於從測試類別執行特定測試方法。
| 參數 | |
|---|---|
methodName |
String |
shouldTestRun
protected boolean shouldTestRun (AnnotatedElement annotatedElement)
檢查有註解的元素是否通過篩選器。公開以進行單元測試。
| 傳回 | |
|---|---|
boolean |
如果測試不應執行,則為 false。 |