收集測試監聽器

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)

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

void testAssumptionFailure ( TestDescription test, FailureDescription failure)

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

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

getMergedTestRunResults

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 >

getNonAssociatedLogFiles

public MultiMap<String, LogFile> getNonAssociatedLogFiles ()

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

退貨
MultiMap <String, LogFile >

getNumAllFailedTestRuns

public int getNumAllFailedTestRuns ()

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

退貨
int

getNumAllFailedTests

public int getNumAllFailedTests ()

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

退貨
int

getNumTestsInState

public int getNumTestsInState (TestResult.TestStatus status)

返回此運行的給定狀態下的測試數。

參數
status TestResult.TestStatus

退貨
int

getNumTotalTests

public int getNumTotalTests ()

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

退貨
int

getPrimaryBuildInfo

public IBuildInfo getPrimaryBuildInfo ()

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

退貨
IBuildInfo

獲取運行結果

public  getRunResults ()

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

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

退貨

getTestRunAtAttempt

public TestRunResult getTestRunAtAttempt (String testRunName, 
                int attempt)

返回一次嘗試的TestRunResult

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

attempt int :嘗試 ID。

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

getTestRunAttemptCount

public int getTestRunAttemptCount (String testRunName)

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

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

退貨
int

getTestRunAttempts

public  getTestRunAttempts (String testRunName)

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

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

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

getTestRunForAttempts

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 : 失敗的ERROR(/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)

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

參數
test TestDescription :標識測試

trace String :失敗的堆棧跟踪

測試假設失敗

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

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

參數
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 :測試結束的時間,通過ERROR(/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 : ERROR(/String)描述運行失敗的原因。

測試運行開始

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

報告測試運行的開始。

參數
name String : 測試運行名稱

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

attemptNumber int : order number,標識同一 runName 多次運行的不同嘗試。 attemptNumber 是從 0 開始索引的,每次發生新的運行時都應該遞增。例如,一個測試被精細地重試了 3 次,它應該在同一個 runName 下總共運行 4 次,並且 attemptNumber 是從 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 : order number,標識同一 runName 多次運行的不同嘗試。 attemptNumber 是從 0 開始索引的,每次發生新的運行時都應該遞增。例如,一個測試被精細地重試了 3 次,它應該在同一個 runName 下總共運行 4 次,並且 attemptNumber 是從 0 到 3。

startTime long :運行開始的時間,通過ERROR(/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 :測試開始的時間,通過ERROR(/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

setIsAggregrateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切換“聚合指標”選項

參數
aggregate boolean