收集测试监听器

public class CollectingTestListener
extends Object implements ITestInvocationListener , ILogSaverListener , IDisableable

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


将收集所有测试结果的ITestInvocationListener

尽管此对象中使用的数据结构是线程安全的,但必须以正确的顺序调用ITestInvocationListener回调。

概括

公共构造函数

CollectingTestListener ()

公共方法

IBuildInfo getBuildInfo ()

此方法已被弃用。依赖getInvocationContext()中的IBuildInfo

TestRunResult getCurrentRunResults ()

获取当前测试运行的结果。

int getExpectedTests ()

返回预期测试计数的数量。

IInvocationContext getInvocationContext ()

返回通过invocationStarted(com.android.tradefed.invoker.IInvocationContext)报告的调用上下文

getMergedTestRunResults ()

返回不同尝试中所有运行的合并结果集合。

IInvocationContext getModuleContextForRunResult (String testRunName)

返回与结果关联的模块的IInvocationContext

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

返回通过invocationStarted(com.android.tradefed.invoker.IInvocationContext)报告的主要构建信息。

getRunResults ()

此方法已被弃用。使用getMergedTestRunResults()

TestRunResult getTestRunAtAttempt (String testRunName, int attempt)

返回单次尝试的TestRunResult

int getTestRunAttemptCount (String testRunName)

返回给定测试运行名称的尝试次数。

getTestRunAttempts (String testRunName)

获取给定测试运行的TestRunResult的所有尝试。

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)

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

void setBuildInfo ( IBuildInfo buildInfo)

此方法已被弃用。不再需要进行测试。

void setDisable (boolean isDisabled)

设置是否应禁用该对象。

void setMergeStrategy ( MergeStrategy strategy)

设置合并结果时要使用的MergeStrategy

void testAssumptionFailure ( TestDescription test, String trace)

当原子测试标记其假定条件为 false 时调用

void testAssumptionFailure ( TestDescription test, FailureDescription failure)

当原子测试标记其假定条件为 false 时调用

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

ERROR(/#testEnded(com.android.tradefed.result.TestDescription,Map))的替代方案,我们可以直接指定结束时间。

void testEnded ( TestDescription test, testMetrics) testEnded ( TestDescription test, testMetrics)

报告单个测试用例的执行结束。

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, runMetrics) testRunEnded (long elapsedTime, runMetrics)

报告测试运行结束。

void testRunFailed ( FailureDescription failure)

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

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)

testStarted(com.android.tradefed.result.TestDescription)的替代方案,其中我们还指定测试开始时间,并结合ERROR(/#testEnded(com.android.tradefed.result.TestDescription,long,Map))进行准确测量。

void testStarted ( TestDescription test)

报告单个测试用例的开始。

受保护的方法

final void clearModuleLogFiles ()

允许清理模块文件,这样我们就可以避免携带它们太久。

final void clearResultsForName (String testRunName)

允许清除给定运行名称的结果。

void setIsAggregrateMetrics (boolean aggregate)

切换“聚合指标”选项

公共构造函数

收集测试监听器

public CollectingTestListener ()

公共方法

获取构建信息

public IBuildInfo getBuildInfo ()

此方法已被弃用。
依赖getInvocationContext()中的IBuildInfo

返回构建信息。

退货
IBuildInfo

获取当前运行结果

public TestRunResult getCurrentRunResults ()

获取当前测试运行的结果。

请注意,结果可能不完整。建议在处理结果之前根据需要测试TestRunResult.isRunComplete()和/或 (@link TestRunResult#isRunFailure()} 的值。

退货
TestRunResult TestRunResult表示上次测试运行期间收集的数据

获取预期测试

public int getExpectedTests ()

返回预期测试计数的数量。如果某些测试未运行,则可能与getNumTotalTests()不同。

退货
int

获取调用上下文

public IInvocationContext getInvocationContext ()

返回通过invocationStarted(com.android.tradefed.invoker.IInvocationContext)报告的调用上下文

退货
IInvocationContext

获取合并测试运行结果

public  getMergedTestRunResults ()

返回不同尝试中所有运行的合并结果集合。

如果有多个结果,则每次测试运行都会合并,最新的测试结果会覆盖之前运行的测试结果。测试运行按尝试次数排序。

同一尝试的指标将根据aggregate-metrics设置的首选项进行合并。最终指标将是最后一次尝试的指标。

退货

getModuleContextForRunResult

public IInvocationContext getModuleContextForRunResult (String testRunName)

返回与结果关联的模块的IInvocationContext

参数
testRunName String :由 { testRunStarted(String, int)给出的名称。

退货
IInvocationContext如果给定测试运行名称没有结果,则该模块的IInvocationContext null

获取模块日志文件

public MultiMap<String, LogFile> getModuleLogFiles ()

返回包含与模块关联的所有记录文件的映射副本

退货
MultiMap <String, LogFile >

获取非关联日志文件

public MultiMap<String, LogFile> getNonAssociatedLogFiles ()

返回映射的副本,其中包含与测试运行或模块无关的所有记录文件。

退货
MultiMap <String, LogFile >

getNumAllFailedTestRuns

public int getNumAllFailedTestRuns ()

返回处于失败状态的测试运行总数

退货
int

获取所有失败测试数

public int getNumAllFailedTests ()

返回处于失败状态的测试总数(仅失败,假设失败不计入)。

退货
int

获取状态测试数

public int getNumTestsInState (TestStatus status)

返回本次运行的给定状态下的测试数量。

参数
status TestStatus

退货
int

获取状态测试数

public int getNumTestsInState (TestResult.TestStatus ddmlibStatus)

为了与旧的状态类型兼容

参数
ddmlibStatus TestResult.TestStatus

退货
int

获取测试总数

public int getNumTotalTests ()

返回所有运行的完整测试总数。

退货
int

获取主要构建信息

public IBuildInfo getPrimaryBuildInfo ()

返回通过invocationStarted(com.android.tradefed.invoker.IInvocationContext)报告的主要构建信息。主要构建是由运行配置的第一个构建提供者返回的构建。如果没有上下文(没有构建测试用例),则返回 null。

退货
IBuildInfo

获取运行结果

public  getRunResults ()

此方法已被弃用。
使用getMergedTestRunResults()

返回所有测试运行的结果。

退货

获取测试运行尝试

public TestRunResult getTestRunAtAttempt (String testRunName, 
                int attempt)

返回单次尝试的TestRunResult

参数
testRunName String :由 { testRunStarted(String, int)给出的名称。

attempt int :尝试 ID。

退货
TestRunResult给定名称和尝试 ID 的TestRunResultnull (如果不存在)。

获取测试运行尝试计数

public int getTestRunAttemptCount (String testRunName)

返回给定测试运行名称的尝试次数。

参数
testRunName String :由 { testRunStarted(String, int)给出的名称。

退货
int

获取测试运行尝试

public  getTestRunAttempts (String testRunName)

获取给定测试运行的TestRunResult的所有尝试。

参数
testRunName String :由 { testRunStarted(String, int)给出的名称。

退货
给定测试运行的所有TestRunResult ,按尝试排序。

获取测试运行尝试

public  getTestRunForAttempts (int attempt)

获取给定尝试的所有结果。

参数
attempt int :我们想要结果的尝试。

退货
给定尝试的所有TestRunResult

获取测试运行名称

public  getTestRunNames ()

返回所有测试运行的所有名称。

这些测试运行可能会以不同的尝试运行多次。

退货

测试失败

public boolean hasFailedTests ()

如果调用有任何失败或假设失败的测试,则返回。

退货
boolean

hasTestRunResultsForName

public boolean hasTestRunResultsForName (String testRunName)

返回给定的测试运行名称是否有任何结果。

参数
testRunName String :由 { testRunStarted(String, int)给出的名称。

退货
boolean

调用结束

public void invocationEnded (long elapsedTime)

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

将由 TradeFederation 框架自动调用。

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

调用失败

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 boolean isDisabled ()

如果整个对象被禁用,则返回 True(跳过设置和拆卸)。否则为假。

退货
boolean

日志关联

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 setBuildInfo (IBuildInfo buildInfo)

此方法已被弃用。
不再需要进行测试。

设置构建信息。应该仅用于测试。

参数
buildInfo IBuildInfo

设置禁用

public void setDisable (boolean isDisabled)

设置是否应禁用该对象。禁用意味着应跳过设置和拆卸步骤。可用于在默认构造函数中默认禁用对象。

参数
isDisabled boolean :对象应处于的状态。

设置合并策略

public void setMergeStrategy (MergeStrategy strategy)

设置合并结果时要使用的MergeStrategy

参数
strategy MergeStrategy

测试假设失败

public void testAssumptionFailure (TestDescription test, 
                String trace)

当原子测试标记其假定条件为 false 时调用

参数
test TestDescription :标识测试

trace String : 失败的堆栈跟踪

测试假设失败

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

当原子测试标记其假定条件为 false 时调用

参数
test TestDescription :标识测试

failure FailureDescription :描述故障及其上下文的FailureDescription

测试结束

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)

测试结束

public void testEnded (TestDescription test, 
                 testMetrics)

报告单个测试用例的执行结束。

如果未调用testFailed(TestDescription, FailureDescription) ,则此测试通过。还返回测试用例执行期间可能发出的任何键/值指标。

参数
test TestDescription :标识测试

testMetrics :发出的指标的ERROR(/Map)

测试失败

public void testFailed (TestDescription test, 
                FailureDescription failure)

报告单个测试用例的失败。

将在 testStarted 和 testEnded 之间调用。

参数
test TestDescription :标识测试

failure FailureDescription :描述故障及其上下文的FailureDescription

测试失败

public void testFailed (TestDescription test, 
                String trace)

报告单个测试用例的失败。

将在 testStarted 和 testEnded 之间调用。

参数
test TestDescription :标识测试

trace String : 失败的堆栈跟踪

测试被忽略

public void testIgnored (TestDescription test)

当测试不会运行时调用,通常是因为测试方法用 org.junit.Ignore 注解。

参数
test TestDescription :标识测试

测试模块结束

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

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

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

测试运行开始

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

报告测试运行的开始。

参数
name String : 测试运行名称

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

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

测试运行开始

public void testRunStarted (String name, 
                int numTests)

报告测试运行的开始。

参数
name String : 测试运行名称

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

测试运行开始

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()测量

测试运行停止

public void testRunStopped (long elapsedTime)

由于用户请求,报告测试运行在完成之前停止。

TODO:当前未使用,考虑删除

参数
elapsedTime long :设备报告的经过时间,以毫秒为单位

测试跳过

public void testSkipped (TestDescription test, 
                SkipReason reason)

当测试因通常意外的原因而被跳过且未执行时调用。将尝试重试这些测试以尝试正确执行。

参数
test TestDescription :标识测试

reason SkipReason : SkipReason

测试开始

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()测量

测试开始

public void testStarted (TestDescription test)

报告单个测试用例的开始。较旧的接口,应尽可能使用testStarted(com.android.tradefed.result.TestDescription)

参数
test TestDescription :标识测试

受保护的方法

清除模块日志文件

protected final void clearModuleLogFiles ()

允许清理模块文件,这样我们就可以避免携带它们太久。

清除名称结果

protected final void clearResultsForName (String testRunName)

允许清除给定运行名称的结果。只应在某些情况下使用,例如结果聚合器。

参数
testRunName String

setIsAggregateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切换“聚合指标”选项

参数
aggregate boolean