分片监听器

public class ShardListener
extends CollectingTestListener implements ISupportGranularResults

java.lang.Object
com.android.tradefed.result.CollectingTestListener
com.android.tradefed.invoker.ShardListener


一个ITestInvocationListener ,用于从调用分片(也称为在多个资源上并行运行的调用拆分)收集结果,并将它们转发到另一个侦听器。

概括

公共构造函数

ShardListener ( ITestInvocationListener main)

创建一个ShardListener

公共方法

getUnderlyingResultReporter ()
void invocationEnded (long elapsedTime)

报告调用已终止,无论是成功还是由于某些错误情况。

void invocationFailed ( FailureDescription failure)

由于某些错误情况而报告不完整的调用。

void invocationFailed (Throwable cause)

由于某些错误情况而报告不完整的调用。

void invocationSkipped ( SkipReason reason)

将调用报告为已跳过

void invocationStarted ( IInvocationContext context)

报告测试调用的开始。

void logAssociation (String dataName, LogFile logFile)

在某些情况下,日志必须与测试用例强关联,但有机会这样做就直接testLogSaved(String, com.android.tradefed.result.LogDataType, com.android.tradefed.result.InputStreamSource, com.android.tradefed.result.LogFile)回调是不可能的。

void setSupportGranularResults (boolean enableGranularResults)
boolean supportGranularResults ()

如果报告器支持精细结果,则返回 True,否则返回 false。

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

提供来自测试调用的关联日志或调试数据。

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

void testModuleEnded ()

报告模块运行结束。

void testModuleStarted ( IInvocationContext moduleContext)

报告模块运行的开始。

void testRunEnded (long elapsedTime, runMetrics) testRunEnded (long elapsedTime, runMetrics)

报告测试运行结束。

void testRunFailed ( FailureDescription failure)

报告测试运行由于FailureDescription描述的故障而未能完成。

void testRunFailed (String failureMessage)

报告测试运行由于致命错误而未能完成。

void testRunStarted (String name, int numTests, int attemptNumber, long startTime)

报告测试运行的开始。

公共构造函数

分片监听器

public ShardListener (ITestInvocationListener main)

创建一个ShardListener

参数
main ITestInvocationListener :应该转发结果的ITestInvocationListener 。为了防止与其他ShardListener发生冲突,该对象在转发结果时将在main上同步。并且只有在调用分片完成后才会发送结果。

公共方法

获取底层结果报告器

public  getUnderlyingResultReporter ()

退货

调用结束

public void invocationEnded (long elapsedTime)

报告调用已终止,无论是成功还是由于某些错误情况。

将由 TradeFederation 框架自动调用。

参数
elapsedTime long :调用所用的时间(以毫秒为单位)

调用失败

public void invocationFailed (FailureDescription failure)

由于某些错误情况而报告不完整的调用。

将由 TradeFederation 框架自动调用。

参数
failure FailureDescription :描述失败原因的FailureDescription

调用失败

public void invocationFailed (Throwable cause)

由于某些错误情况而报告不完整的调用。

将由 TradeFederation 框架自动调用。

参数
cause Throwable :失败的Throwable原因

调用已跳过

public void invocationSkipped (SkipReason reason)

将调用报告为已跳过

参数
reason SkipReason

调用开始

public void invocationStarted (IInvocationContext context)

报告测试调用的开始。

将由 TradeFederation 框架自动调用。记者需要重写此方法以支持多设备报告。

参数
context IInvocationContext :有关调用的信息

日志关联

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 setSupportGranularResults (boolean enableGranularResults)

参数
enableGranularResults boolean

支持粒度结果

public boolean supportGranularResults ()

如果报告器支持精细结果,则返回 True,否则返回 false。

退货
boolean

测试日志

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 方法完成。

测试日志已保存

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

参数
dataName String

dataType LogDataType

dataStream InputStreamSource

logFile LogFile

测试模块结束

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 failureMessage)

报告测试运行由于致命错误而未能完成。

参数
failureMessage String :描述运行失败原因的String

测试运行开始

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

报告测试运行的开始。

参数
name String : 测试运行名称

numTests int : 测试运行中的测试总数

attemptNumber int :订单号,标识同一 runName 多次运行的不同尝试。 attemptsNumber 是从 0 开始索引的,并且每次新的运行发生时都应该递增。例如,一个测试被粒度重试 3 次,它应该在同一 runName 下总共运行 4 次,并且 attemptsNumber 从 0 到 3。

startTime long :运行开始的时间,通过System.currentTimeMillis()测量