BugreportCollector

public class BugreportCollector
extends Object implements ITestInvocationListener

java.lang.Object
   ↳ com.android.tradefed.result.BugreportCollector


在可設定事件發生時收集錯誤報告的傳遞 ITestInvocationListener,然後在收集每個錯誤報告後對其子項呼叫 ITestInvocationListener.testLog

行為:(FIXME:完成這項作業)

  • 在任何測試案例失敗後擷取
  • 在每個測試案例後擷取
  • 在每個失敗的測試案例後擷取
  • 擷取

摘要

巢狀類別

class BugreportCollector.Predicate

完整的述詞,說明擷取錯誤報告的時機。 

interface BugreportCollector.SubPredicate

 

欄位

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

在每個失敗的測試套件之後觸發的預先定義判定式

public static final BugreportCollector.Predicate AT_START

預先定義的述詞,會在第一個叫用開始時觸發

公用建構函式

BugreportCollector(ITestInvocationListener listener, ITestDevice testDevice)

公用方法

void addPredicate(BugreportCollector.Predicate p)
void blockUntilIdle()

阻斷,直到收集器不再收集任何錯誤報告。

TestSummary getSummary()

允許 InvocationListener 傳回摘要。

void invocationEnded(long elapsedTime)

回報叫用已終止,無論是成功或因某些錯誤條件而終止。

void invocationFailed(Throwable cause)

由於某些錯誤情況,系統會回報未完成的叫用作業。

void invocationStarted(IInvocationContext context)

回報測試叫用作業的開始時間。

void setAsynchronous(boolean asynchronous)

設定錯誤報告收集功能應在不同的執行緒中收集錯誤報告 (asynchronous = true),還是在擷取到錯誤報告前封鎖呼叫端 (asynchronous = false)。

void setDescriptiveName(String name)

設定記錄錯誤報告時要使用的描述性名稱。

void setDeviceWaitTime(int waitTime)

設定裝置上線的等待時間 (以秒為單位),以便我們嘗試擷取錯誤報告。

void testAssumptionFailure(TestDescription test, String trace)

當原子測試標記假設條件為 false 時,系統會呼叫此方法

void testEnded(TestDescription test, testMetrics)

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

void testFailed(TestDescription test, String trace)

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

void testIgnored(TestDescription test)

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

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

提供測試叫用作業的相關記錄或偵錯資料。

void testRunEnded(long elapsedTime, runMetrics)

回報測試執行結束。

void testRunFailed(String errorMessage)

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

void testRunStarted(String runName, int testCount)

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

void testRunStopped(long elapsedTime)

報表測試在使用者要求下,在完成前停止執行。

void testStarted(TestDescription test)

回報個別測試案例的開始時間。

欄位

AFTER_FAILED_TESTCASES

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

在每個失敗的測試案例後觸發的預先定義謂詞

AT_START

public static final BugreportCollector.Predicate AT_START

預先定義的述詞,會在第一個叫用作業開始時觸發

公用建構函式

BugreportCollector

public BugreportCollector (ITestInvocationListener listener, 
                ITestDevice testDevice)

參數
listener ITestInvocationListener

testDevice ITestDevice

公用方法

addPredicate

public void addPredicate (BugreportCollector.Predicate p)

參數
p BugreportCollector.Predicate

blockUntilIdle

public void blockUntilIdle ()

阻斷,直到收集器不再收集任何錯誤報告為止。如果收集器未主動收集錯誤報告,請立即傳回

getSummary

public TestSummary getSummary ()

允許 InvocationListener 傳回摘要。

傳回
TestSummary 摘要執行作業的 TestSummary,或空值

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:叫用作業相關資訊

setAsynchronous

public void setAsynchronous (boolean asynchronous)

設定錯誤報告收集功能應在不同的執行緒中收集錯誤報告 (asynchronous = true),還是在擷取到錯誤報告前封鎖呼叫端 (asynchronous = false)。

參數
asynchronous boolean

setDescriptiveName

public void setDescriptiveName (String name)

設定記錄錯誤報告時要使用的描述性名稱。如果為 nullBugreportCollector 就會改為執行預設行為,也就是將導致收集錯誤報告的事件名稱序列化。

參數
name String

setDeviceWaitTime

public void setDeviceWaitTime (int waitTime)

設定裝置上線的等待時間 (以秒為單位),然後嘗試擷取錯誤報告。如果為否,則不會執行檢查。系統會記錄並忽略在這個檢查期間遇到的任何 DeviceNotAvailableException

參數
waitTime int

testAssumptionFailure

public void testAssumptionFailure (TestDescription test, 
                String trace)

當原子測試標記假設條件為 false 時,系統會呼叫此方法

參數
test TestDescription:用於識別測試

trace String:失敗的堆疊追蹤

testEnded

public void testEnded (TestDescription test, 
                 testMetrics)

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

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

參數
test TestDescription:用於識別測試

testMetrics :傳送指標的 ERROR(/Map)

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:用於識別測試

testLog

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

提供測試叫用作業的相關記錄或偵錯資料。

必須在 ERROR(/ITestInvocationListener#invocationFailed(Throwable))ERROR(/ITestInvocationListener#invocationEnded(long)) 之前呼叫

TradeFederation 架構會自動呼叫這個方法,提供主機記錄,並在適用情況下提供裝置 Logcat。

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

dataType LogDataType:資料的 LogDataType

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

testRunEnded

public void testRunEnded (long elapsedTime, 
                 runMetrics)

回報測試執行結束。

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

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

testRunFailed

public void testRunFailed (String errorMessage)

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

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

testRunStarted

public void testRunStarted (String runName, 
                int testCount)

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

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

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

testRunStopped

public void testRunStopped (long elapsedTime)

報表測試在使用者要求下,在完成前停止執行。

TODO:目前未使用,建議移除

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

testStarted

public void testStarted (TestDescription test)

回報個別測試案例的開始時間。較舊的介面,應盡可能使用 testStarted(com.android.tradefed.result.TestDescription)

參數
test TestDescription:用於識別測試