ModuleListener
public
class
ModuleListener
extends CollectingTestListener
| java.lang.Object | ||
| ↳ | com.android.tradefed.result.CollectingTestListener | |
| ↳ | com.android.tradefed.testtype.suite.ModuleListener | |
附加至每個模組的每個 IRemoteTest 的監聽器,用於收集結果清單。
摘要
公用建構函式 | |
|---|---|
ModuleListener(ITestInvocationListener listener, IInvocationContext moduleContext)
建構函式。 |
|
公用方法 | |
|---|---|
boolean
|
hasLastAttemptFailed()
傳回監聽器上次重試工作階段是否失敗。 |
void
|
logAssociation(String dataName, LogFile logFile)
在某些情況下,記錄必須與測試案例密切相關,但無法在直接 |
void
|
setAttemptIsolation(CurrentInvocation.IsolationGrade isolation)
設定是否應將嘗試回報為已隔離。 |
void
|
setCollectTestsOnly(boolean collectTestsOnly)
設定是否只收集測試。 |
void
|
setMarkTestsSkipped(boolean skip)
是否要將所有測試案例標示為略過。 |
void
|
setTestMappingSources(List<String> testMappingSources)
設定要插入指標的測試對應來源。 |
void
|
setUseModuleResultsForwarder(boolean useModuleResultsForwarder)
|
void
|
testAssumptionFailure(TestDescription test, String trace)
當原子測試標記假設為 false 的條件時,系統會呼叫這個函式 |
void
|
testAssumptionFailure(TestDescription test, FailureDescription failure)
當原子測試標記假設為 false 的條件時,系統會呼叫這個函式 |
void
|
testEnded(TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)
回報個別測試案例的執行結束時間。 |
void
|
testEnded(TestDescription test, long endTime, HashMap<String, MetricMeasurement.Metric> testMetrics)
|
void
|
testFailed(TestDescription test, FailureDescription failure)
回報個別測試案例的失敗情形。 |
void
|
testFailed(TestDescription test, String trace)
回報個別測試案例的失敗情形。 |
void
|
testIgnored(TestDescription test)
當測試不會執行時呼叫,通常是因為測試方法以 org.junit.Ignore 註解標註。 |
void
|
testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)
|
void
|
testLogSaved(String dataName, LogDataType dataType, InputStreamSource dataStream, LogFile logFile)
|
void
|
testRunEnded(long elapsedTime, HashMap<String, MetricMeasurement.Metric> runMetrics)
Reports end of test run. |
void
|
testRunFailed(FailureDescription failure)
由於 |
void
|
testRunFailed(String errorMessage)
發生嚴重錯誤,因此無法完成報表測試執行。 |
void
|
testRunStarted(String name, int numTests, int attemptNumber)
回報測試執行的開始。 |
void
|
testRunStarted(String name, int numTests, int attemptNumber, long startTime)
回報測試執行的開始。 |
void
|
testSkipped(TestDescription test, SkipReason reason)
Called when a test is skipped and did not execute for a reason that is not usually expected. |
void
|
testStarted(TestDescription test, long startTime)
|
公用建構函式
ModuleListener
public ModuleListener (ITestInvocationListener listener, IInvocationContext moduleContext)
建構函式。
| 參數 | |
|---|---|
listener |
ITestInvocationListener |
moduleContext |
IInvocationContext |
公用方法
hasLastAttemptFailed
public boolean hasLastAttemptFailed ()
傳回接聽器上次重試工作階段是否失敗。
| 傳回 | |
|---|---|
boolean |
|
logAssociation
public void logAssociation (String dataName,
LogFile logFile)在某些情況下,記錄必須與測試案例密切相關,但無法在直接 testLogSaved(String,LogDataType,InputStreamSource,LogFile) 回呼中執行此操作。因此,這個回呼可明確提供強關聯。
| 參數 | |
|---|---|
dataName |
String:資料名稱 |
logFile |
LogFile:先前記錄的 LogFile,應與測試案例建立關聯。 |
setAttemptIsolation
public void setAttemptIsolation (CurrentInvocation.IsolationGrade isolation)
設定是否應將嘗試回報為已隔離。
| 參數 | |
|---|---|
isolation |
CurrentInvocation.IsolationGrade |
setCollectTestsOnly
public void setCollectTestsOnly (boolean collectTestsOnly)
設定是否只收集測試。
| 參數 | |
|---|---|
collectTestsOnly |
boolean |
setMarkTestsSkipped
public void setMarkTestsSkipped (boolean skip)
是否要將所有測試案例標示為略過。
| 參數 | |
|---|---|
skip |
boolean |
setTestMappingSources
public void setTestMappingSources (List<String> testMappingSources)
設定要插入指標的測試對應來源。
| 參數 | |
|---|---|
testMappingSources |
List |
setUseModuleResultsForwarder
public void setUseModuleResultsForwarder (boolean useModuleResultsForwarder)
| 參數 | |
|---|---|
useModuleResultsForwarder |
boolean |
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, HashMap<String, MetricMeasurement.Metric> testMetrics)
回報個別測試案例的執行結束時間。
如果未叫用 testFailed(TestDescription, FailureDescription),這項測試就會通過。也會傳回測試案例執行期間可能發出的任何鍵/值指標。
| 參數 | |
|---|---|
test |
TestDescription:識別測試 |
testMetrics |
HashMap:發出的指標 Map |
testEnded
public void testEnded (TestDescription test, long endTime, HashMap<String, MetricMeasurement.Metric> testMetrics)
testEnded(TestDescription,Map) 的替代方案,可直接指定結束時間。搭配 testStarted(TestDescription,long) 使用,可準確測量。
| 參數 | |
|---|---|
test |
TestDescription:識別測試 |
endTime |
long:測試結束時間,透過 System.currentTimeMillis() 測量 |
testMetrics |
HashMap:發出的指標 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:識別測試 |
testLog
public void testLog (String dataName,
LogDataType dataType,
InputStreamSource dataStream)| 參數 | |
|---|---|
dataName |
String |
dataType |
LogDataType |
dataStream |
InputStreamSource |
testLogSaved
public void testLogSaved (String dataName,
LogDataType dataType,
InputStreamSource dataStream,
LogFile logFile)| 參數 | |
|---|---|
dataName |
String |
dataType |
LogDataType |
dataStream |
InputStreamSource |
logFile |
LogFile |
testRunEnded
public void testRunEnded (long elapsedTime,
HashMap<String, MetricMeasurement.Metric> runMetrics)測試執行結束時會回報。FIXME:我們無法使用不同型別的兩個 Map<> 介面,因此必須在此使用 HashMap。
| 參數 | |
|---|---|
elapsedTime |
long:裝置回報的經過時間 (以毫秒為單位) |
runMetrics |
HashMap:在測試執行結束時,使用 Metric 報告的鍵/值組合。 |
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,
int attemptNumber,
long startTime)回報測試執行的開始時間。
| 參數 | |
|---|---|
name |
String:測試執行名稱 |
numTests |
int:測試執行作業中的測試總數 |
attemptNumber |
int:訂單號碼,用於識別多次執行的相同 runName 的不同嘗試。attemptNumber 是以 0 為索引,每次執行新作業時都應遞增。舉例來說,如果測試精細重試 3 次,則在相同 runName 下應有 4 次執行,且 attemptNumber 為 0 到 3。 |
startTime |
long:跑步開始時間,透過 System.currentTimeMillis() 測量 |
testSkipped
public 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 |
SkipReason:SkipReason |
testStarted
public void testStarted (TestDescription test, long startTime)
testStarted(TestDescription) 的替代方案,我們也會指定測試開始時間,並搭配 testEnded(TestDescription,long,Map) 進行準確的評估。
| 參數 | |
|---|---|
test |
TestDescription:識別測試 |
startTime |
long:測試開始時間,透過 System.currentTimeMillis() 測量 |