收集測試監聽器
public class CollectingTestListener
extends Object
implements ITestInvocationListener , ILogSaverListener , IDisableable
java.lang.Object | |
↳ | com.android.tradefed.result.CollectingTestListener |
將收集所有測試結果的ITestInvocationListener
。
儘管此物件中使用的資料結構是線程安全的,但必須以正確的順序呼叫ITestInvocationListener
回呼。
概括
公共構造函數 | |
---|---|
CollectingTestListener () |
公共方法 | |
---|---|
IBuildInfo | getBuildInfo () 此方法已被棄用。依賴 |
TestRunResult | getCurrentRunResults () 取得目前測試運行的結果。 |
int | getExpectedTests () 傳回預期測試計數的數量。 |
IInvocationContext | getInvocationContext () 傳回透過 |
getMergedTestRunResults () 傳回不同嘗試中所有運行的合併結果集合。 | |
IInvocationContext | getModuleContextForRunResult (String testRunName) 傳回與結果關聯的模組的 |
MultiMap <String, LogFile > | getModuleLogFiles () 傳回包含與模組關聯的所有記錄檔案的對應副本 |
MultiMap <String, LogFile > | getNonAssociatedLogFiles () 傳回映射的副本,其中包含與測試運行或模組無關的所有記錄檔案。 |
int | getNumAllFailedTestRuns () 傳回處於失敗狀態的測試運行總數 |
int | getNumAllFailedTests () 傳回處於失敗狀態的測試總數(僅失敗,假設失敗不計入)。 |
int | getNumTestsInState (TestResult.TestStatus status) 傳回本次運行的給定狀態下的測試數量。 |
int | getNumTotalTests () 傳回所有運行的完整測試總數。 |
IBuildInfo | getPrimaryBuildInfo () 傳回透過 |
getRunResults () 此方法已被棄用。使用 | |
TestRunResult | getTestRunAtAttempt (String testRunName, int attempt) 傳回單次嘗試的 |
int | getTestRunAttemptCount (String testRunName) 傳回給定測試運行名稱的嘗試次數。 |
getTestRunAttempts (String testRunName) 取得給定測試運行的 | |
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) 在某些情況下,日誌必須與測試案例強關聯,但有機會這樣做就直接 |
void | setBuildInfo ( IBuildInfo buildInfo) 此方法已被棄用。不再需要進行測試。 |
void | setDisable (boolean isDisabled) 設定是否應禁用該物件。 |
void | setMergeStrategy ( MergeStrategy strategy) 設定合併結果時要使用的 |
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) |
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) 報告測試運行由於 |
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) |
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 IInvocationContext getInvocationContext ()
傳回透過invocationStarted(com.android.tradefed.invoker.IInvocationContext)
報告的呼叫上下文
退貨 | |
---|---|
IInvocationContext |
取得合併測試運行結果
publicgetMergedTestRunResults ()
傳回不同嘗試中所有運行的合併結果集合。
如果有多個結果,則每次測試運行都會合併,最新的測試結果會覆蓋先前執行的測試結果。測試運行按嘗試次數排序。
同一嘗試的指標將根據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 TestRunResult getTestRunAtAttempt (String testRunName, int attempt)
傳回單次嘗試的TestRunResult
。
參數 | |
---|---|
testRunName | String :由 { testRunStarted(String, int) 給出的名稱。 |
attempt | int :嘗試 ID。 |
退貨 | |
---|---|
TestRunResult | 給定名稱和嘗試 ID 的TestRunResult 或null (如果不存在)。 |
取得測試運行嘗試計數
public int getTestRunAttemptCount (String testRunName)
傳回給定測試運行名稱的嘗試次數。
參數 | |
---|---|
testRunName | String :由 { testRunStarted(String, int) 給出的名稱。 |
退貨 | |
---|---|
int |
取得測試運行嘗試
publicgetTestRunAttempts (String testRunName)
取得給定測試運行的TestRunResult
的所有嘗試。
參數 | |
---|---|
testRunName | String :由 { testRunStarted(String, int) 給出的名稱。 |
退貨 | |
---|---|
給定測試運行的所有TestRunResult ,按嘗試排序。 |
取得測試運行嘗試
publicgetTestRunForAttempts (int attempt)
取得給定嘗試的所有結果。
參數 | |
---|---|
attempt | int :我們想要結果的嘗試。 |
退貨 | |
---|---|
給定嘗試的所有TestRunResult 。 |
取得測試運行名稱
publicgetTestRunNames ()
傳回所有測試運行的所有名稱。
這些測試運行可能會以不同的嘗試運行多次。
退貨 | |
---|---|
測試失敗
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 |