BasePostProcessor

public abstract class BasePostProcessor
extends Object implements IPostProcessor

java.lang.Object
   ↳ com.android.tradefed.postprocessor.BasePostProcessor


所有實作項目都應擴充的基礎 IPostProcessor。請確保在最終結果回報器之前呼叫後續處理方法。

摘要

公用建構函式

BasePostProcessor()

公用方法

final ITestInvocationListener init(ITestInvocationListener listener)

後處理器的初始化步驟。

final void invocationEnded(long elapsedTime)

回報是否因成功或發生錯誤而終止呼叫。

final void invocationFailed(FailureDescription failure)

Reports an incomplete invocation due to some error condition.

final void invocationFailed(Throwable cause)

Reports an incomplete invocation due to some error condition.

void invocationSkipped(SkipReason reason)

將叫用作業回報為已略過

final void invocationStarted(IInvocationContext context)

轉送的叫用事件監聽器

final boolean isDisabled()

如果整個物件都已停用 (略過設定和終止),則傳回 True。

final void logAssociation(String dataName, LogFile logFile)

在某些情況下,記錄必須與測試案例密切相關,但無法在直接 testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile) 回呼中執行此操作。

更新記錄與測試的關聯。

processAllTestMetricsAndLogs(ListMultimap<String, MetricMeasurement.Metric> allTestMetrics, allTestLogs)

實作這個方法,即可匯總所有測試的指標和記錄。

abstract processRunMetricsAndLogs( rawMetrics, runLogs)

實作這個方法,從現有指標和記錄產生一組新指標。

processTestMetricsAndLogs(TestDescription testDescription, testMetrics, testLogs)

導入這個方法,即可後續處理各項測試的指標和記錄。

final void setLogSaver(ILogSaver logSaver)

設定 ILogSaver,允許實作者儲存檔案。

void setUp()

在子項後處理器中覆寫這個方法,以便在測試執行前初始化。

final void testAssumptionFailure(TestDescription test, String trace)

當原子測試標記假設條件為 false 時,系統會呼叫這個函式。

final void testAssumptionFailure(TestDescription test, FailureDescription failure)

當原子測試標記假設條件為 false 時,系統會呼叫這個函式。

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

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

final void testEnded(TestDescription test, testMetrics)

回報個別測試案例的執行結束時間。

final void testFailed(TestDescription test, FailureDescription failure)

回報個別測試案例的失敗情形。

final void testFailed(TestDescription test, String trace)

回報個別測試案例的失敗情形。

final void testIgnored(TestDescription test)

Called when a test will not be run, generally because a test method is annotated with org.junit.Ignore.

final void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)

使用這個方法,從 PostProcessor 實作項目記錄檔案。

final void testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)

測試記錄儲存完畢時呼叫。

final void testModuleEnded()

回報模組執行作業的結束時間。

final void testModuleStarted(IInvocationContext moduleContext)

回報模組的執行開始時間。

final void testRunEnded(long elapsedTime, runMetrics)

Reports end of test run.

final void testRunFailed(FailureDescription failure)

由於 FailureDescription 所述的失敗情形,報表測試執行作業無法完成。

final void testRunFailed(String errorMessage)

由於發生嚴重錯誤,報表測試執行作業無法完成。

final void testRunStarted(String runName, int testCount, int attemptNumber)

回報測試執行的開始時間。

final void testRunStarted(String runName, int testCount)

測試執行回呼

final void testRunStarted(String runName, int testCount, int attemptNumber, long startTime)

回報測試執行的開始時間。

final void testRunStopped(long elapsedTime)

由於使用者要求,報表測試執行作業在完成前停止。

final void testSkipped(TestDescription test, SkipReason reason)

Called when a test is skipped and did not execute for a reason that is not usually expected.

final void testStarted(TestDescription test, long startTime)

testStarted(com.android.tradefed.result.TestDescription) 的替代方案,我們也會指定測試開始時間,並搭配 ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map)) 進行準確的評估。

final void testStarted(TestDescription test)

測試案例回呼

受保護的方法

void cleanUp()
MetricMeasurement.DataType getMetricType()

如有需要,請覆寫這個方法來變更指標類型。

String getRunName()

公用建構函式

BasePostProcessor

public BasePostProcessor ()

公用方法

init

public final ITestInvocationListener init (ITestInvocationListener listener)

後處理器的初始化步驟。確保在任何測試回呼之前呼叫。

參數
listener ITestInvocationListener

傳回
ITestInvocationListener

invocationEnded

public final void invocationEnded (long elapsedTime)

回報是否因某些錯誤狀況而終止呼叫 (無論是否成功)。

TradeFederation 架構會自動呼叫。

參數
elapsedTime long:以毫秒為單位的呼叫經過時間

invocationFailed

public final void invocationFailed (FailureDescription failure)

Reports an incomplete invocation due to some error condition.

TradeFederation 架構會自動呼叫。

參數
failure FailureDescription:說明失敗原因的 FailureDescription

invocationFailed

public final void invocationFailed (Throwable cause)

由於發生錯誤狀況,因此回報不完整的叫用。

TradeFederation 架構會自動呼叫。

參數
cause ThrowableThrowable 失敗的 Throwable 原因

invocationSkipped

public void invocationSkipped (SkipReason reason)

將叫用作業回報為已略過

參數
reason SkipReason

invocationStarted

public final void invocationStarted (IInvocationContext context)

轉送的叫用事件監聽器

參數
context IInvocationContext:叫用相關資訊

isDisabled

public final boolean isDisabled ()

如果整個物件都已停用 (略過設定和終止),則傳回 True。否則傳回「false」。

傳回
boolean

logAssociation

public final 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,應與測試案例建立關聯。

processAllTestMetricsAndLogs

public  processAllTestMetricsAndLogs (ListMultimap<String, MetricMeasurement.Metric> allTestMetrics, 
                 allTestLogs)

實作這個方法,即可匯總所有測試的指標和記錄。這個方法產生的指標會回報為執行指標。只應傳回新產生的指標,且金鑰名稱不得重複 (不得與現有金鑰發生衝突)。

參數
allTestMetrics ListMultimap:HashMultimap,用於儲存每個測試的指標,並依指標名稱分組。

allTestLogs :地圖,用於儲存每個測試的記錄檔地圖,並以資料名稱做為鍵,使用每個測試的 TestDescription 做為鍵。

傳回
所有測試指標中新產生的指標集。

processRunMetricsAndLogs

public abstract  processRunMetricsAndLogs ( rawMetrics, 
                 runLogs)

請實作這個方法,從現有指標和記錄產生一組新指標。系統只會傳回新產生的指標,且金鑰名稱不得重複 (不得與現有金鑰發生衝突)。

參數
rawMetrics :可供執行的原始指標集。

runLogs :測試執行的記錄檔集。

傳回
從執行指標產生的一組新指標。

processTestMetricsAndLogs

public  processTestMetricsAndLogs (TestDescription testDescription, 
                 testMetrics, 
                 testLogs)

導入這個方法,即可後續處理各項測試的指標和記錄。只應傳回新產生的指標,且金鑰名稱不得重複 (不得與現有金鑰發生衝突)。

參數
testDescription TestDescription:描述測試的 TestDescription 物件。

testMetrics :測試的一組指標。

testLogs :測試期間記錄的一組檔案。

傳回
從測試指標新產生的一組指標。

setLogSaver

public final void setLogSaver (ILogSaver logSaver)

設定 ILogSaver,允許實作者儲存檔案。

參數
logSaver ILogSaverILogSaver

setUp

public void setUp ()

在子項後置處理器中覆寫這個方法,即可在測試執行前進行初始化。

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                String trace)

當原子測試標記假設為 false 的條件時呼叫

參數
test TestDescription:識別測試

trace String:失敗的堆疊追蹤

testAssumptionFailure

public final void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

當原子測試標記假設為 false 的條件時呼叫

參數
test TestDescription:識別測試

failure FailureDescriptionFailureDescription,說明失敗情形和相關情境。

testEnded

public final 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 final void testEnded (TestDescription test, 
                 testMetrics)

回報個別測試案例的執行結束時間。

如果未叫用 testFailed(TestDescription, FailureDescription),這項測試就會通過。也會傳回在測試案例執行期間可能發出的任何鍵/值指標。

參數
test TestDescription:識別測試

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

testFailed

public final void testFailed (TestDescription test, 
                FailureDescription failure)

回報個別測試案例的失敗情形。

會在 testStarted 和 testEnded 之間呼叫。

參數
test TestDescription:識別測試

failure FailureDescriptionFailureDescription,說明失敗情形和相關情境。

testFailed

public final void testFailed (TestDescription test, 
                String trace)

回報個別測試案例的失敗情形。

會在 testStarted 和 testEnded 之間呼叫。

參數
test TestDescription:識別測試

trace String:失敗的堆疊追蹤

testIgnored

public final void testIgnored (TestDescription test)

當測試不會執行時呼叫,通常是因為測試方法已使用 org.junit.Ignore 註解。

參數
test TestDescription:識別測試

testLog

public final void testLog (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream)

使用這個方法,從 PostProcessor 實作記錄檔案。

參數
dataName String:資料的String說明名稱,例如「device_logcat」。注意:dataName 在每次呼叫時可能不具唯一性,也就是說,實作者必須能夠處理具有相同 dataName 的多項呼叫。

dataType LogDataType:資料的 LogDataType

dataStream InputStreamSource:資料的 InputStreamSource。實作者應呼叫 createInputStream 開始讀取資料,並確保在完成時關閉產生的 InputStream。呼叫端應確保資料來源持續存在且可供存取,直到 testLog 方法完成為止。

testLogSaved

public final void testLogSaved (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream, 
                LogFile logFile)

測試記錄儲存完畢時呼叫。

應取代 ITestInvocationListener.testLog(String, LogDataType, InputStreamSource) 使用。

參數
dataName String:資料的String說明名稱,例如「device_logcat」。注意:dataName 在每次呼叫時可能不具唯一性,也就是說,實作者必須能夠處理具有相同 dataName 的多項呼叫。

dataType LogDataType:資料的 LogDataType

dataStream InputStreamSource:資料的 InputStreamSource。實作者應呼叫 createInputStream 開始讀取資料,並確保在完成時關閉產生的 InputStream。

logFile LogFile:包含已儲存檔案中繼資料的 LogFile

testModuleEnded

public final void testModuleEnded ()

回報模組執行作業的結束時間。

testModuleStarted

public final void testModuleStarted (IInvocationContext moduleContext)

回報模組的執行開始時間。這個回呼與 testModuleEnded() 相關聯,且在序列中為選用項目。只有在使用模組的執行期間,才會使用這個標記:以套件為基礎的執行器。

參數
moduleContext IInvocationContext:模組的 IInvocationContext

testRunEnded

public final void testRunEnded (long elapsedTime, 
                 runMetrics)

報告測試執行結束時間。

參數
elapsedTime long:裝置回報的經過時間 (以毫秒為單位)

runMetrics :在測試執行結束時回報的鍵/值組合

testRunFailed

public final void testRunFailed (FailureDescription failure)

由於 FailureDescription 所述的失敗情形,報表測試執行作業無法完成。

參數
failure FailureDescriptionFailureDescription,說明失敗情形和相關情境。

testRunFailed

public final void testRunFailed (String errorMessage)

發生嚴重錯誤,導致報表測試執行作業無法完成。

參數
errorMessage StringString,說明執行失敗的原因。

testRunStarted

public final void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber)

回報測試執行的開始時間。

參數
runName String:測試執行作業名稱

testCount int:測試執行作業中的測試總數

attemptNumber int:訂單號碼,用於識別相同 runName 的不同嘗試,該 runName 會多次執行。attemptNumber 是以 0 為索引,每次執行新作業時都應遞增。舉例來說,如果測試細部重試 3 次,則在相同 runName 下應有 4 次執行作業,且 attemptNumber 為 0 到 3。

testRunStarted

public final void testRunStarted (String runName, 
                int testCount)

測試執行回呼

參數
runName String:測試執行作業名稱

testCount int:測試執行作業中的測試總數

testRunStarted

public final void testRunStarted (String runName, 
                int testCount, 
                int attemptNumber, 
                long startTime)

回報測試執行的開始時間。

參數
runName String:測試執行作業名稱

testCount int:測試執行作業中的測試總數

attemptNumber int:訂單號碼,用於識別相同 runName 的不同嘗試,該 runName 會多次執行。attemptNumber 是以 0 為索引,每次執行新作業時都應遞增。舉例來說,如果測試細部重試 3 次,則在相同 runName 下應有 4 次執行作業,且 attemptNumber 為 0 到 3。

startTime long:跑步開始時間,透過 System.currentTimeMillis() 測量

testRunStopped

public final void testRunStopped (long elapsedTime)

由於使用者要求,報表測試執行作業在完成前停止。

TODO:目前未使用,考慮移除

參數
elapsedTime long:裝置回報的經過時間 (以毫秒為單位)

testSkipped

public final void testSkipped (TestDescription test, 
                SkipReason reason)

Called when a test is skipped and did not execute for a reason that is not usually expected. 系統會嘗試重試這些測試,以確保正常執行。

參數
test TestDescription:識別測試

reason SkipReasonSkipReason

testStarted

public final 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 final void testStarted (TestDescription test)

測試案例回呼

參數
test TestDescription:識別測試

受保護的方法

cleanUp

protected void cleanUp ()

getMetricType

protected MetricMeasurement.DataType getMetricType ()

如有需要,請覆寫這個方法來變更指標類型。預設指標為已處理的類型。

傳回
MetricMeasurement.DataType

getRunName

protected String getRunName ()

傳回
String