收集測試監聽器

public class CollectingTestListener
extends Object implements ITestInvocationListener , ILogSaverListener , IDisableable

java.lang.Object
com.android.tradefed.result.CollectingTestListener


將收集所有測試結果的ITestInvocationListener

儘管此對像中使用的數據結構是線程安全的,但必須以正確的順序調用ITestInvocationListener回調。

概括

公共構造函數

CollectingTestListener ()

公共方法

IBuildInfo getBuildInfo ()

此方法已被棄用。依賴getInvocationContext()中的IBuildInfo

TestRunResult getCurrentRunResults ()

獲取當前測試運行的結果。

int getExpectedTests ()

返回預期測試計數的數量。

IInvocationContext getInvocationContext ()

返回通過invocationStarted(com.android.tradefed.invoker.IInvocationContext)報告的調用上下文

getMergedTestRunResults ()

返回不同嘗試中所有運行的合併結果集合。

IInvocationContext getModuleContextForRunResult (String testRunName)

返回與結果關聯的模塊的IInvocationContext

MultiMap <String, LogFile > getModuleLogFiles ()

返回包含與模塊關聯的所有記錄文件的映射副本

MultiMap <String, LogFile > getNonAssociatedLogFiles ()

返回映射的副本,其中包含與測試運行或模塊無關的所有記錄文件。

int getNumAllFailedTestRuns ()

返回處於失敗狀態的測試運行總數

int getNumAllFailedTests ()

返回處於失敗狀態的測試總數(僅失敗,假設失敗不計入)。

int getNumTestsInState (TestResult.TestStatus status)

返回本次運行的給定狀態下的測試數量。

int getNumTotalTests ()

返回所有運行的完整測試總數。

IBuildInfo getPrimaryBuildInfo ()

返回通過invocationStarted(com.android.tradefed.invoker.IInvocationContext)報告的主要構建信息。

getRunResults ()

此方法已被棄用。使用getMergedTestRunResults()

TestRunResult getTestRunAtAttempt (String testRunName, int attempt)

返回單次嘗試的TestRunResult

int getTestRunAttemptCount (String testRunName)

返回給定測試運行名稱的嘗試次數。

getTestRunAttempts (String testRunName)

獲取給定測試運行的TestRunResult的所有嘗試。

getTestRunForAttempts (int attempt)

獲取給定嘗試的所有結果。

getTestRunNames ()

返回所有測試運行的所有名稱。

boolean hasFailedTests ()

如果調用有任何失敗或假設失敗的測試,則返回。

boolean hasTestRunResultsForName (String testRunName)

返回給定的測試運行名稱是否有任何結果。

void invocationEnded (long elapsedTime)

報告調用已終止,無論是成功還是由於某些錯誤情況。

void invocationFailed (Throwable cause)

由於某些錯誤情況而報告不完整的調用。

void invocationStarted ( IInvocationContext context)

報告測試調用的開始。

boolean isDisabled ()

如果整個對像被禁用(跳過設置和拆卸),則返回 True。

void logAssociation (String dataName, LogFile logFile)

在某些情況下,日誌必須與測試用例強關聯,但有機會這樣做就直接testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile)回調是不可能的。

void setBuildInfo ( IBuildInfo buildInfo)

此方法已被棄用。不再需要進行測試。

void setDisable (boolean isDisabled)

設置是否應禁用該對象。

void setMergeStrategy ( MergeStrategy strategy)

設置合併結果時要使用的MergeStrategy

void testAssumptionFailure ( TestDescription test, String trace)

當原子測試標記其假定條件為 false 時調用

void testAssumptionFailure ( TestDescription test, FailureDescription failure)

當原子測試標記其假定條件為 false 時調用

void testEnded ( TestDescription test, long endTime, testMetrics) testEnded ( TestDescription test, long endTime, testMetrics)

ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map))的替代方案,我們可以直接指定結束時間。

void testEnded ( TestDescription test, testMetrics) testEnded ( TestDescription test, testMetrics)

報告單個測試用例的執行結束。

void testFailed ( TestDescription test, FailureDescription failure)

報告單個測試用例的失敗。

void testFailed ( TestDescription test, String trace)

報告單個測試用例的失敗。

void testIgnored ( TestDescription test)

當測試不會運行時調用,通常是因為測試方法用 org.junit.Ignore 註解。

void testModuleEnded ()

報告模塊運行結束。

void testModuleStarted ( IInvocationContext moduleContext)

報告模塊運行的開始。

void testRunEnded (long elapsedTime, runMetrics) testRunEnded (long elapsedTime, runMetrics)

報告測試運行結束。

void testRunFailed ( FailureDescription failure)

報告測試運行由於FailureDescription描述的故障而未能完成。

void testRunFailed (String errorMessage)

報告測試運行由於致命錯誤而未能完成。

void testRunStarted (String name, int numTests, int attemptNumber)

報告測試運行的開始。

void testRunStarted (String name, int numTests)

報告測試運行的開始。

void testRunStarted (String name, int numTests, int attemptNumber, long startTime)

報告測試運行的開始。

void testRunStopped (long elapsedTime)

由於用戶請求,報告測試運行在完成之前停止。

void testStarted ( TestDescription test, long startTime)

testStarted(com.android.tradefed.result.TestDescription)的替代方案,其中我們還指定測試開始時間,並結合ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map))進行準確測量。

void testStarted ( TestDescription test)

報告單個測試用例的開始。

受保護的方法

final void clearModuleLogFiles ()

允許清理模塊文件,這樣我們就可以避免攜帶它們太久。

final void clearResultsForName (String testRunName)

允許清除給定運行名稱的結果。

void setIsAggregrateMetrics (boolean aggregate)

切換“聚合指標”選項

公共構造函數

收集測試監聽器

public CollectingTestListener ()

公共方法

獲取構建信息

public IBuildInfo getBuildInfo ()

此方法已被棄用。
依賴getInvocationContext()中的IBuildInfo

返回構建信息。

退貨
IBuildInfo

獲取當前運行結果

public TestRunResult getCurrentRunResults ()

獲取當前測試運行的結果。

請注意,結果可能不完整。建議在處理結果之前根據需要測試TestRunResult.isRunComplete()和/或 (@link TestRunResult#isRunFailure()} 的值。

退貨
TestRunResult TestRunResult表示上次測試運行期間收集的數據

獲取預期測試

public int getExpectedTests ()

返回預期測試計數的數量。如果某些測試未運行,則可能與getNumTotalTests()不同。

退貨
int

獲取調用上下文

public IInvocationContext getInvocationContext ()

返回通過invocationStarted(com.android.tradefed.invoker.IInvocationContext)報告的調用上下文

退貨
IInvocationContext

獲取合併測試運行結果

public  getMergedTestRunResults ()

返回不同嘗試中所有運行的合併結果集合。

如果有多個結果,則每次測試運行都會合併,最新的測試結果會覆蓋以前運行的測試結果。測試運行按嘗試次數排序。

同一嚐試的指標將根據aggregate-metrics設置的首選項進行合併。最終指標將是最後一次嘗試的指標。

退貨

getModuleContextForRunResult

public IInvocationContext getModuleContextForRunResult (String testRunName)

返回與結果關聯的模塊的IInvocationContext

參數
testRunName String :由 { testRunStarted(String, int)給出的名稱。

退貨
IInvocationContext如果給定測試運行名稱沒有結果,則該模塊的IInvocationContext null

獲取模塊日誌文件

public MultiMap<String, LogFile> getModuleLogFiles ()

返回包含與模塊關聯的所有記錄文件的映射副本

退貨
MultiMap <String, LogFile >

獲取非關聯日誌文件

public MultiMap<String, LogFile> getNonAssociatedLogFiles ()

返回映射的副本,其中包含與測試運行或模塊無關的所有記錄文件。

退貨
MultiMap <String, LogFile >

getNumAllFailedTestRuns

public int getNumAllFailedTestRuns ()

返回處於失敗狀態的測試運行總數

退貨
int

獲取所有失敗測試數

public int getNumAllFailedTests ()

返回處於失敗狀態的測試總數(僅失敗,假設失敗不計入)。

退貨
int

獲取狀態測試數

public int getNumTestsInState (TestResult.TestStatus status)

返回本次運行的給定狀態下的測試數量。

參數
status TestResult.TestStatus

退貨
int

獲取測試總數

public int getNumTotalTests ()

返回所有運行的完整測試總數。

退貨
int

獲取主要構建信息

public IBuildInfo getPrimaryBuildInfo ()

返回通過invocationStarted(com.android.tradefed.invoker.IInvocationContext)報告的主要構建信息。主要構建是由運行配置的第一個構建提供者返回的構建。如果沒有上下文(沒有構建測試用例),則返回 null。

退貨
IBuildInfo

獲取運行結果

public  getRunResults ()

此方法已被棄用。
使用getMergedTestRunResults()

返回所有測試運行的結果。

退貨

獲取測試運行嘗試

public TestRunResult getTestRunAtAttempt (String testRunName, 
                int attempt)

返回單次嘗試的TestRunResult

參數
testRunName String :由 { testRunStarted(String, int)給出的名稱。

attempt int :嘗試 ID。

退貨
TestRunResult給定名稱和嘗試 ID 的TestRunResultnull (如果不存在)。

獲取測試運行嘗試計數

public int getTestRunAttemptCount (String testRunName)

返回給定測試運行名稱的嘗試次數。

參數
testRunName String :由 { testRunStarted(String, int)給出的名稱。

退貨
int

獲取測試運行嘗試

public  getTestRunAttempts (String testRunName)

獲取給定測試運行的TestRunResult的所有嘗試。

參數
testRunName String :由 { testRunStarted(String, int)給出的名稱。

退貨
給定測試運行的所有TestRunResult ,按嘗試排序。

獲取測試運行嘗試

public  getTestRunForAttempts (int attempt)

獲取給定嘗試的所有結果。

參數
attempt int :我們想要結果的嘗試。

退貨
給定嘗試的所有TestRunResult

獲取測試運行名稱

public  getTestRunNames ()

返回所有測試運行的所有名稱。

這些測試運行可能會以不同的嘗試運行多次。

退貨

測試失敗

public boolean hasFailedTests ()

如果調用有任何失敗或假設失敗的測試,則返回。

退貨
boolean

hasTestRunResultsForName

public boolean hasTestRunResultsForName (String testRunName)

返回給定的測試運行名稱是否有任何結果。

參數
testRunName String :由 { testRunStarted(String, int)給出的名稱。

退貨
boolean

調用結束

public void invocationEnded (long elapsedTime)

報告調用已終止,無論是成功還是由於某些錯誤情況。

將由 TradeFederation 框架自動調用。

參數
elapsedTime long :調用所用的時間(以毫秒為單位)

調用失敗

public void invocationFailed (Throwable cause)

由於某些錯誤情況而報告不完整的調用。

將由 TradeFederation 框架自動調用。

參數
cause Throwable :失敗的Throwable原因

調用開始

public void invocationStarted (IInvocationContext context)

報告測試調用的開始。

將由 TradeFederation 框架自動調用。記者需要重寫此方法以支持多設備報告。

參數
context IInvocationContext :有關調用的信息

被禁用

public boolean isDisabled ()

如果整個對像被禁用(跳過設置和拆卸),則返回 True。否則為假。

退貨
boolean

日誌關聯

public void logAssociation (String dataName, 
                LogFile logFile)

在某些情況下,日誌必須與測試用例強關聯,但有機會這樣做就直接testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile)回調是不可能的。因此,此回調允許顯式提供強關聯。

參數
dataName String : 數據的名稱

logFile LogFile :之前記錄的LogFile ,應與測試用例關聯。

設置構建信息

public void setBuildInfo (IBuildInfo buildInfo)

此方法已被棄用。
不再需要進行測試。

設置構建信息。應該僅用於測試。

參數
buildInfo IBuildInfo

設置禁用

public void setDisable (boolean isDisabled)

設置是否應禁用該對象。禁用意味著應跳過設置和拆卸步驟。可用於在默認構造函數中默認禁用對象。

參數
isDisabled boolean :對象應處於的狀態。

設置合併策略

public void setMergeStrategy (MergeStrategy strategy)

設置合併結果時要使用的MergeStrategy

參數
strategy MergeStrategy

測試假設失敗

public void testAssumptionFailure (TestDescription test, 
                String trace)

當原子測試標記其假定條件為 false 時調用

參數
test TestDescription :標識測試

trace String : 失敗的堆棧跟踪

測試假設失敗

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

當原子測試標記其假定條件為 false 時調用

參數
test TestDescription :標識測試

failure FailureDescription :描述故障及其上下文的FailureDescription

測試結束

public void testEnded (TestDescription test, 
                long endTime, 
                 testMetrics)

ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map))的替代方案,我們可以直接指定結束時間。與testStarted(com.android.tradefed.result.TestDescription, long)結合使用以進行準確測量。

參數
test TestDescription :標識測試

endTime long :測試結束的時間,通過System.currentTimeMillis()測量

testMetrics :發出的指標的ERROR(/Map)

測試結束

public void testEnded (TestDescription test, 
                 testMetrics)

報告單個測試用例的執行結束。

如果未調用testFailed(TestDescription, FailureDescription) ,則此測試通過。還返回測試用例執行期間可能發出的任何鍵/值指標。

參數
test TestDescription :標識測試

testMetrics :發出的指標的ERROR(/Map)

測試失敗

public void testFailed (TestDescription test, 
                FailureDescription failure)

報告單個測試用例的失敗。

將在 testStarted 和 testEnded 之間調用。

參數
test TestDescription :標識測試

failure FailureDescription :描述故障及其上下文的FailureDescription

測試失敗

public void testFailed (TestDescription test, 
                String trace)

報告單個測試用例的失敗。

將在 testStarted 和 testEnded 之間調用。

參數
test TestDescription :標識測試

trace String : 失敗的堆棧跟踪

測試被忽略

public void testIgnored (TestDescription test)

當測試不會運行時調用,通常是因為測試方法用 org.junit.Ignore 註解。

參數
test TestDescription :標識測試

測試模塊結束

public void testModuleEnded ()

報告模塊運行結束。

測試模塊啟動

public void testModuleStarted (IInvocationContext moduleContext)

報告模塊運行的開始。此回調與testModuleEnded()關聯,並且在序列中是可選的。它僅在使用模塊的運行期間使用:基於套件的運行器。

參數
moduleContext IInvocationContext :模塊的IInvocationContext

測試運行結束

public void testRunEnded (long elapsedTime, 
                 runMetrics)

報告測試運行結束。 FIXME:我們不能有兩個不同類型的 Map<> 接口,所以我們必須在這裡使用 HashMap。

參數
elapsedTime long :設備報告的經過時間,以毫秒為單位

runMetrics :使用Metric測試運行結束時報告的鍵值對。

測試運行失敗

public void testRunFailed (FailureDescription failure)

報告測試運行由於FailureDescription描述的故障而未能完成。

參數
failure FailureDescription :描述故障及其上下文的FailureDescription

測試運行失敗

public void testRunFailed (String errorMessage)

報告測試運行由於致命錯誤而未能完成。

參數
errorMessage String :描述運行失敗原因的String

測試運行開始

public void testRunStarted (String name, 
                int numTests, 
                int attemptNumber)

報告測試運行的開始。

參數
name String : 測試運行名稱

numTests int : 測試運行中的測試總數

attemptNumber int :訂單號,標識同一 runName 多次運行的不同嘗試。 attemptsNumber 是從 0 開始索引的,並且每次新的運行發生時都應該遞增。例如,一個測試被粒度重試 3 次,它應該在同一 runName 下總共運行 4 次,並且 attemptsNumber 從 0 到 3。

測試運行開始

public void testRunStarted (String name, 
                int numTests)

報告測試運行的開始。

參數
name String : 測試運行名稱

numTests int : 測試運行中的測試總數

測試運行開始

public void testRunStarted (String name, 
                int numTests, 
                int attemptNumber, 
                long startTime)

報告測試運行的開始。

參數
name String : 測試運行名稱

numTests int : 測試運行中的測試總數

attemptNumber int :訂單號,標識同一 runName 多次運行的不同嘗試。 attemptsNumber 是從 0 開始索引的,並且每次新的運行發生時都應該遞增。例如,一個測試被粒度重試 3 次,它應該在同一 runName 下總共運行 4 次,並且 attemptsNumber 從 0 到 3。

startTime long :運行開始的時間,通過System.currentTimeMillis()測量

測試運行停止

public void testRunStopped (long elapsedTime)

由於用戶請求,報告測試運行在完成之前停止。

TODO:當前未使用,考慮刪除

參數
elapsedTime long :設備報告的經過時間,以毫秒為單位

測試開始

public void testStarted (TestDescription test, 
                long startTime)

testStarted(com.android.tradefed.result.TestDescription)的替代方案,其中我們還指定測試開始時間,並結合ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map))進行準確測量。

參數
test TestDescription :標識測試

startTime long :測試開始的時間,通過System.currentTimeMillis()測量

測試開始

public void testStarted (TestDescription test)

報告單個測試用例的開始。較舊的接口,應盡可能使用testStarted(com.android.tradefed.result.TestDescription)

參數
test TestDescription :標識測試

受保護的方法

清除模塊日誌文件

protected final void clearModuleLogFiles ()

允許清理模塊文件,這樣我們就可以避免攜帶它們太久。

清除名稱結果

protected final void clearResultsForName (String testRunName)

允許清除給定運行名稱的結果。僅應在某些情況下使用,例如結果聚合器。

參數
testRunName String

setIsAggregateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切換“聚合指標”選項

參數
aggregate boolean