CollectingTestListener
  public
  
  
  
  class
  CollectingTestListener
  
    extends Object
  
  
  
  
  
      implements
      
        IDisableable, 
      
        ILogSaverListener, 
      
        ITestInvocationListener
      
  
  
| 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(TestStatus status)
      傳回此執行作業中處於指定狀態的測試數量。 | 
| 
        
        
        
        
        
        int | 
      getNumTestsInState(TestResult.TestStatus ddmlibStatus)
      如要與舊版狀態類型相容 | 
| 
        
        
        
        
        
        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 | 
      invocationSkipped(SkipReason reason)
      將叫用動作回報為略過 | 
| 
        
        
        
        
        
        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, 
 | 
| 
        
        
        
        
        
        void | 
      testEnded(TestDescription test, 回報個別測試案例的執行結束時間。 | 
| 
        
        
        
        
        
        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, 回報測試執行結束。 | 
| 
        
        
        
        
        
        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 | 
      testSkipped(TestDescription test, SkipReason reason)
      當測試遭到略過,且未因通常預期的原因而執行時,系統會呼叫此方法。 | 
| 
        
        
        
        
        
        void | 
      testStarted(TestDescription test, long startTime)
      
 | 
| 
        
        
        
        
        
        void | 
      testStarted(TestDescription test)
      回報個別測試案例的開始時間。 | 
| 受保護的方法 | |
|---|---|
| 
        
        
        
        final
        
        void | 
      clearModuleLogFiles()
      允許清除模組檔案,避免保留太久。 | 
| 
        
        
        
        final
        
        void | 
      clearResultsForName(String testRunName)
      可清除指定執行名稱的結果。 | 
| 
        
        
        
        final
        
        void | 
      clearTestRunResults()
      允許清除所有測試執行結果,避免保留太久。 | 
| 
        
        
        
        
        
        void | 
      setIsAggregrateMetrics(boolean aggregate)
      切換「匯總指標」選項 | 
公用建構函式
CollectingTestListener
public CollectingTestListener ()
公用方法
getBuildInfo
public IBuildInfo getBuildInfo ()
      This method is deprecated.
    依附於 getInvocationContext() 的 IBuildInfo。
傳回建構資訊。
| 傳回 | |
|---|---|
| IBuildInfo | |
getCurrentRunResults
public TestRunResult getCurrentRunResults ()
取得目前測試執行結果。
請注意,結果可能不完整。建議您在處理結果前,先測試 TestRunResult.isRunComplete() 的值和/或 (@link TestRunResult#isRunFailure()})。
| 傳回 | |
|---|---|
| TestRunResult | TestRunResult代表上次執行測試時收集的資料 | 
getExpectedTests
public int getExpectedTests ()
傳回預期測試次數。如果部分測試未執行,可能會與 getNumTotalTests() 不同。
| 傳回 | |
|---|---|
| int | |
getInvocationContext
public IInvocationContext getInvocationContext ()
傳回透過 invocationStarted(com.android.tradefed.invoker.IInvocationContext) 回報的叫用程序內容
| 傳回 | |
|---|---|
| IInvocationContext | |
getMergedTestRunResults
publicgetMergedTestRunResults () 
針對不同嘗試的所有執行作業,傳回合併的結果集合。
如果有多個結果,系統會合併每項測試,最新的測試結果會覆寫先前測試的結果。測試執行作業會依嘗試次數排序。
系統會根據 aggregate-metrics 設定的偏好設定,合併相同嘗試的指標。最終指標會是上次嘗試的指標。
| 傳回 | |
|---|---|
|  | |
getModuleContextForRunResult
public IInvocationContext getModuleContextForRunResult (String testRunName)
傳回與結果相關聯的模組 IInvocationContext。
| 參數 | |
|---|---|
| testRunName | String:{testRunStarted(String, int)} 提供的名稱。 | 
| 傳回 | |
|---|---|
| IInvocationContext | 如果指定的測試執行名稱 null沒有任何結果,則為該模組的IInvocationContext。 | 
getModuleLogFiles
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 (TestStatus status)
傳回此執行作業中處於指定狀態的測試數量。
| 參數 | |
|---|---|
| status | TestStatus | 
| 傳回 | |
|---|---|
| int | |
getNumTestsInState
public int getNumTestsInState (TestResult.TestStatus ddmlibStatus)
與舊版狀態類型相容
| 參數 | |
|---|---|
| ddmlibStatus | TestResult.TestStatus | 
| 傳回 | |
|---|---|
| int | |
getNumTotalTests
public int getNumTotalTests ()
傳回所有執行作業的完成測試總數。
| 傳回 | |
|---|---|
| int | |
getPrimaryBuildInfo
public IBuildInfo getPrimaryBuildInfo ()
傳回透過 invocationStarted(com.android.tradefed.invoker.IInvocationContext) 回報的主要版本資訊。主要版本是執行設定的第一個版本提供者傳回的版本。如果沒有結構定義 (沒有建構至測試案例),則會傳回空值。
| 傳回 | |
|---|---|
| IBuildInfo | |
getRunResults
publicgetRunResults () 
      This method is deprecated.
    使用 getMergedTestRunResults()
    
傳回所有測試執行結果。
| 傳回 | |
|---|---|
|  | |
getTestRunAtAttempt
public TestRunResult getTestRunAtAttempt (String testRunName, int attempt)
針對單一嘗試傳回 TestRunResult。
| 參數 | |
|---|---|
| testRunName | String:{testRunStarted(String, int)} 提供的名稱。 | 
| attempt | int:嘗試 ID。 | 
| 傳回 | |
|---|---|
| TestRunResult | 指定名稱和嘗試 ID 的 TestRunResult,如果不存在則為null。 | 
getTestRunAttemptCount
public int getTestRunAttemptCount (String testRunName)
傳回指定測試執行名稱的嘗試次數。
| 參數 | |
|---|---|
| testRunName | String:{testRunStarted(String, int)} 提供的名稱。 | 
| 傳回 | |
|---|---|
| int | |
getTestRunAttempts
publicgetTestRunAttempts (String testRunName) 
取得指定測試執行作業的 TestRunResult 所有嘗試次數。
| 參數 | |
|---|---|
| testRunName | String:{testRunStarted(String, int)} 提供的名稱。 | 
| 傳回 | |
|---|---|
|  | 指定測試執行作業的所有 TestRunResult,按嘗試次數排序。 | 
getTestRunForAttempts
publicgetTestRunForAttempts (int attempt) 
取得指定嘗試次數的所有結果。
| 參數 | |
|---|---|
| attempt | int:我們要取得結果的嘗試次數。 | 
| 傳回 | |
|---|---|
|  | 指定嘗試次數的所有 TestRunResult。 | 
getTestRunNames
publicgetTestRunNames () 
傳回所有測試執行作業的所有名稱。
這些測試可能會在不同嘗試中執行多次。
| 傳回 | |
|---|---|
|  | |
hasFailedTests
public boolean hasFailedTests ()
傳回叫用是否有任何失敗或假設失敗的測試。
| 傳回 | |
|---|---|
| boolean | |
hasTestRunResultsForName
public boolean hasTestRunResultsForName (String testRunName)
傳回特定測試執行名稱是否有任何結果。
| 參數 | |
|---|---|
| testRunName | String:{testRunStarted(String, int)} 提供的名稱。 | 
| 傳回 | |
|---|---|
| boolean | |
invocationEnded
public void invocationEnded (long elapsedTime)
回報叫用已終止,無論是成功或因某些錯誤情況而終止。
會由 TradeFederation 架構自動呼叫。
| 參數 | |
|---|---|
| elapsedTime | long:叫用作業的經過時間 (以毫秒為單位) | 
invocationFailed
public void invocationFailed (Throwable cause)
因某些錯誤情況而回報不完整的叫用。
會由 TradeFederation 架構自動呼叫。
| 參數 | |
|---|---|
| cause | Throwable:失敗的Throwable原因 | 
invocationStarted
public void invocationStarted (IInvocationContext context)
回報測試叫用作業的開始時間。
會由 TradeFederation 架構自動呼叫。回報器需要覆寫這個方法,才能支援多裝置回報。
| 參數 | |
|---|---|
| context | IInvocationContext:叫用作業相關資訊 | 
isDisabled
public boolean isDisabled ()
如果整個物件已停用 (略過設定和拆卸),則傳回 True。否則為 False。
| 傳回 | |
|---|---|
| boolean | |
logAssociation
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,應與測試案例相關聯。 | 
setBuildInfo
public void setBuildInfo (IBuildInfo buildInfo)
      This method is deprecated.
    測試時不再需要。
設定建構資訊。僅供測試使用。
| 參數 | |
|---|---|
| buildInfo | IBuildInfo | 
setDisable
public void setDisable (boolean isDisabled)
設定是否應停用物件。停用表示應略過設定和拆卸步驟。可用於在預設建構函式中,讓物件預設為停用。
| 參數 | |
|---|---|
| isDisabled | boolean:物件應放置的狀態。 | 
setMergeStrategy
public void setMergeStrategy (MergeStrategy strategy)
設定要用於合併結果的 MergeStrategy。
| 參數 | |
|---|---|
| strategy | MergeStrategy | 
testAssumptionFailure
public void testAssumptionFailure (TestDescription test, String trace)
當原子測試標記假設條件為 false 時,系統會呼叫此方法
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| trace | String:失敗的堆疊追蹤 | 
testAssumptionFailure
public void testAssumptionFailure (TestDescription test, FailureDescription failure)
當原子測試標記假設條件為 false 時,系統會呼叫此方法
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| failure | FailureDescription:FailureDescription可說明失敗和相關情境。 | 
testEnded
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) | 
testEnded
public void testEnded (TestDescription test,testMetrics) 
回報個別測試案例的執行結束時間。
如果未叫用 testFailed(TestDescription, FailureDescription),則表示這項測試已通過。也會傳回在測試案例執行期間可能已發出的任何鍵/值指標。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| testMetrics | :傳送指標的ERROR(/Map) | 
testFailed
public void testFailed (TestDescription test, FailureDescription failure)
回報個別測試案例的失敗情形。
會在 testStarted 和 testEnded 之間呼叫。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| failure | FailureDescription:FailureDescription可說明失敗和相關情境。 | 
testFailed
public void testFailed (TestDescription test, String trace)
回報個別測試案例的失敗情形。
會在 testStarted 和 testEnded 之間呼叫。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| trace | String:失敗的堆疊追蹤 | 
testIgnored
public void testIgnored (TestDescription test)
當測試不會執行時,系統會呼叫此方法,通常是因為測試方法已標註為 org.junit.Ignore。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
testModuleEnded
public void testModuleEnded ()
回報模組執行作業結束。
testModuleStarted
public void testModuleStarted (IInvocationContext moduleContext)
回報模組開始執行的時間。這個回呼與 testModuleEnded() 相關聯,在序列中為選用項目。只有在使用模組:套件式執行程式的執行期間才會使用。
| 參數 | |
|---|---|
| moduleContext | IInvocationContext:模組的IInvocationContext。 | 
testRunEnded
public void testRunEnded (long elapsedTime, 
                 runMetrics) 回報測試執行結束。
| 參數 | |
|---|---|
| elapsedTime | long:裝置回報的經過時間,以毫秒為單位 | 
| runMetrics | :測試執行結束時回報的鍵/值組合 | 
testRunFailed
public void testRunFailed (FailureDescription failure)
由於 FailureDescription 所述的錯誤,導致報表測試執行作業無法完成。
| 參數 | |
|---|---|
| failure | FailureDescription:FailureDescription可說明失敗和相關情境。 | 
testRunFailed
public void testRunFailed (String errorMessage)
由於發生致命錯誤,因此無法完成報表測試執行作業。
| 參數 | |
|---|---|
| errorMessage | String:String,說明執行失敗的原因。 | 
testRunStarted
public void testRunStarted (String name, 
                int numTests, 
                int attemptNumber)回報測試執行作業的開始時間。
| 參數 | |
|---|---|
| name | String:測試執行作業名稱 | 
| numTests | int:測試執行作業中的測試總數 | 
| attemptNumber | int:訂單號碼,用於識別同一個 runName 執行多次的不同嘗試。attemptNumber 的索引為 0,每次執行時都應遞增。舉例來說,如果測試以細部重試 3 次,則在相同的 runName 下應有 4 次執行,而 attemptNumber 則從 0 到 3。 | 
testRunStarted
public void testRunStarted (String name, 
                int numTests)回報測試執行作業的開始時間。
| 參數 | |
|---|---|
| name | String:測試執行作業名稱 | 
| numTests | int:測試執行作業中的測試總數 | 
testRunStarted
public void testRunStarted (String name, 
                int numTests, 
                int attemptNumber, 
                long startTime)回報測試執行作業的開始時間。
| 參數 | |
|---|---|
| name | String:測試執行作業名稱 | 
| numTests | int:測試執行作業中的測試總數 | 
| attemptNumber | int:訂單號碼,用於識別同一個 runName 執行多次的不同嘗試。attemptNumber 的索引為 0,每次執行新測試時,應增加 1。舉例來說,如果測試細部重試 3 次,則在相同的 runName 下,應有 4 次總執行次數,而 attemptNumber 則從 0 到 3。 | 
| startTime | long:透過System.currentTimeMillis()測量的執行時間 | 
testRunStopped
public void testRunStopped (long elapsedTime)
報表測試在使用者要求下,在完成前停止執行。
TODO:目前未使用,建議移除
| 參數 | |
|---|---|
| elapsedTime | long:裝置回報的經過時間,以毫秒為單位 | 
testSkipped
public void testSkipped (TestDescription test, SkipReason reason)
當測試遭到略過,且未因通常預期的原因而執行時,系統會呼叫此方法。系統會嘗試重試這些測試,以便取得正確的執行結果。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
| reason | SkipReason:SkipReason | 
testStarted
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()測量 | 
testStarted
public void testStarted (TestDescription test)
回報個別測試案例的開始時間。較舊的介面,應盡可能使用 testStarted(com.android.tradefed.result.TestDescription)。
| 參數 | |
|---|---|
| test | TestDescription:用於識別測試 | 
受保護的方法
clearModuleLogFiles
protected final void clearModuleLogFiles ()
允許清除模組檔案,避免保留太久。
clearResultsForName
protected final void clearResultsForName (String testRunName)
可清除指定執行名稱的結果。僅適用於某些情況,例如結果匯總器。
| 參數 | |
|---|---|
| testRunName | String | 
clearTestRunResults
protected final void clearTestRunResults ()
允許清除所有測試執行結果,避免保留太久。
setIsAggregrateMetrics
protected void setIsAggregrateMetrics (boolean aggregate)
切換「匯總指標」選項
| 參數 | |
|---|---|
| aggregate | boolean | 
