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( notAnnotations)

新增註解的 ERROR(/Set),如果測試標示了該註解,就會排除這些註解。

void addAllExcludeFilters( filters)

新增要排除的測試篩選器 ERROR(/Set)

void addAllIncludeAnnotation( annotations)

新增註解的 ERROR(/Set),以便在測試標記時納入。

void addAllIncludeFilters( filters)

新增要納入測試的篩選器 ERROR(/Set)

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()

getClassNames()
ITestDevice getDevice()

取得受測裝置。

getExcludeAnnotations()

傳回要排除的註解目前 ERROR(/Set)

getExcludeFilters()

傳回排除篩選器的目前 ERROR(/Set)

getIncludeAnnotations()

傳回要加入的註解目前 ERROR(/Set)

getIncludeFilters()

傳回包含篩選器的目前 ERROR(/Set)

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)

注入使用的 IConfiguration

void setDevice(ITestDevice device)

注入受測裝置。

static void setOptionToLoadedObject(Object testObj, keyValueOptions)

裝置執行器輔助程式,可從 set-option 設定選項,方式與 HostTest 相同。

void setTestInformation(TestInformation testInfo)
split(Integer shardCount, TestInformation testInfo)

我們會依測試類別或方法,將測試結果依個人分開。

受保護的方法

HostTest createHostTest(Class<?> classObj)

分片時建立 HostTest 執行個體的輔助程式。

IBuildInfo getBuild()

取得 HostTest 收到的建構資訊。

ClassLoader getClassLoader()

傳回預設類別載入器。

final 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)

清除並設定要執行的類別名稱。

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 ( notAnnotations)

如果測試標示了註解,則新增要排除的註解 ERROR(/Set)

參數
notAnnotations

addAllExcludeFilters

public void addAllExcludeFilters ( filters)

新增要排除的測試篩選器 ERROR(/Set)

參數
filters

addAllIncludeAnnotation

public void addAllIncludeAnnotation ( annotations)

新增 ERROR(/Set) 註解,以便在測試標示該註解時納入。

參數
annotations

addAllIncludeFilters

public void addAllIncludeFilters ( filters)

新增要納入測試的篩選器 ERROR(/Set)

參數
filters

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

getAbi

public IAbi getAbi ()

傳回
IAbi

getClassNames

public  getClassNames ()

傳回

getDevice

public ITestDevice getDevice ()

取得受測裝置。

傳回
ITestDevice ITestDevice

getExcludeAnnotations

public  getExcludeAnnotations ()

傳回要排除的註解目前 ERROR(/Set)

傳回

getExcludeFilters

public  getExcludeFilters ()

傳回排除篩選器的目前 ERROR(/Set)

傳回

getIncludeAnnotations

public  getIncludeAnnotations ()

傳回要納入的註解目前 ERROR(/Set)

傳回

getIncludeFilters

public  getIncludeFilters ()

傳回包含篩選器的目前 ERROR(/Set)

傳回

getRuntimeHint

public long getRuntimeHint ()

以毫秒為單位傳回測試的預期執行時間。這段時間用於平衡分片執行作業的負載

傳回
long

得分

public void run (TestInformation testInfo, 
                ITestInvocationListener listener)

執行測試,並向接聽程式回報結果。

參數
testInfo TestInformation:包含執行測試的實用資訊的 TestInformation 物件。

listener ITestInvocationListener:測試結果的 ITestInvocationListener

擲回
DeviceNotAvailableException

setAbi

public void setAbi (IAbi abi)

參數
abi IAbi

setBuild

public void setBuild (IBuildInfo buildInfo)

參數
buildInfo IBuildInfo

setCollectTestsOnly

public void setCollectTestsOnly (boolean shouldCollectTest)

啟用或停用測試收集模式

setConfiguration

public void setConfiguration (IConfiguration configuration)

插入使用的 IConfiguration

參數
configuration IConfiguration

setDevice

public void setDevice (ITestDevice device)

注入測試裝置。

參數
device ITestDevice:要使用的 ITestDevice

setOptionToLoadedObject

public static void setOptionToLoadedObject (Object testObj, 
                 keyValueOptions)

裝置執行器可使用這個輔助程式,從 set-option 設定選項,方式與 HostTest 相同。

參數
testObj Object:將接收選項的物件。

keyValueOptions :以 HostTest 設定選項格式設定的選項清單。

setTestInformation

public void setTestInformation (TestInformation testInfo)

參數
testInfo TestInformation

拆分

public  split (Integer shardCount, 
                TestInformation testInfo)

我們會依測試類別或方法,將測試結果分給個別使用者。

參數
shardCount Integer:嘗試的 Shard 數量。

testInfo TestInformation:父項 TestInformation

傳回
要個別執行的子測試集合,或測試目前無法分片時的 null

受保護的方法

createHostTest

protected HostTest createHostTest (Class<?> classObj)

在分片時建立 HostTest 執行個體的輔助程式。覆寫以從 HostTest 傳回任何子項。

參數
classObj Class

傳回
HostTest

getBuild

protected IBuildInfo getBuild ()

取得 HostTest 收到的建構資訊。

傳回
IBuildInfo IBuildInfo

getClassLoader

protected ClassLoader getClassLoader ()

傳回預設類別載入器。

傳回
ClassLoader

getClasses

protected final  getClasses ()

傳回

getJarFile

protected File getJarFile (String jarName, 
                TestInformation testInfo)

檢查不同用途的構件通常所在的多個位置,找出 JAR 檔案。

參數
jarName String

testInfo TestInformation

傳回
File

hasJUnit4Annotation

protected boolean hasJUnit4Annotation (Class<?> classObj)

Helper to determine if we are dealing with a Test class with Junit4 annotations.

參數
classObj Class

傳回
boolean

loadObject

protected Object loadObject (Class<?> classObj)

載入類別物件並設定測試資訊 (裝置、建構)。

參數
classObj Class

傳回
Object

setClassName

protected void setClassName (String className)

清除然後設定要執行的類別名稱。

參數
className String

shouldTestRun

protected boolean shouldTestRun (AnnotatedElement annotatedElement)

檢查具有註解的元素是否通過篩選器。公開以進行單元測試。

傳回
boolean 如果測試不應執行,則為 false。