CollectingTestListener

public class CollectingTestListener
extends Object implements IDisableable, ILogSaverListener, ITestInvocationListener

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) 报告的主要 build 信息。

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)

当原子测试标记为假的假设条件时调用

void testAssumptionFailure(TestDescription test, FailureDescription failure)

当原子测试标记为假的假设条件时调用

void testEnded(TestDescription test, long endTime, testMetrics)

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

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

报告测试运行结束。

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)

切换“汇总指标”选项

公共构造函数

CollectingTestListener

public CollectingTestListener ()

公共方法

getBuildInfo

public IBuildInfo getBuildInfo ()

此方法已废弃。
依赖于 getInvocationContext() 中的 IBuildInfo

返回 build 信息。

返回
IBuildInfo

getCurrentRunResults

public TestRunResult getCurrentRunResults ()

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

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

返回
TestRunResult TestRunResult,表示上次测试运行期间收集的数据

getExpectedTests

public int getExpectedTests ()

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

返回
int

getInvocationContext

public IInvocationContext getInvocationContext ()

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

返回
IInvocationContext

getMergedTestRunResults

public  getMergedTestRunResults ()

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

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

系统会根据 aggregate-metrics 设置的偏好设置,合并同一尝试的相关指标。最终指标将是上次尝试的指标。

返回

getModuleContextForRunResult

public IInvocationContext getModuleContextForRunResult (String testRunName)

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

参数
testRunName String:{testRunStarted(String, int)} 提供的名称。

返回
IInvocationContext 如果没有针对给定测试运行名称 null 的结果,则为该模块的 IInvocationContext

getModuleLogFiles

public MultiMap<String, LogFile> getModuleLogFiles ()

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

返回
MultiMap<String, LogFile>

getNonAssociatedLogFiles

public MultiMap<String, LogFile> getNonAssociatedLogFiles ()

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

返回
MultiMap<String, LogFile>

getNumAllFailedTestRuns

public int getNumAllFailedTestRuns ()

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

返回
int

getNumAllFailedTests

public int getNumAllFailedTests ()

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

返回
int

getNumTestsInState

public int getNumTestsInState (TestStatus status)

返回此运行作业中处于给定状态的测试数量。

参数
status TestStatus

返回
int

getNumTestsInState

public int getNumTestsInState (TestResult.TestStatus ddmlibStatus)

为了与旧版状态类型兼容

参数
ddmlibStatus TestResult.TestStatus

返回
int

getNumTotalTests

public int getNumTotalTests ()

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

返回
int

getPrimaryBuildInfo

public IBuildInfo getPrimaryBuildInfo ()

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

返回
IBuildInfo

getRunResults

public  getRunResults ()

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

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

返回

getTestRunAtAttempt

public TestRunResult getTestRunAtAttempt (String testRunName, 
                int attempt)

针对单次尝试返回 TestRunResult

参数
testRunName String:{testRunStarted(String, int)} 提供的名称。

attempt int:尝试 ID。

返回
TestRunResult 给定名称和尝试 ID 的 TestRunResult,如果不存在,则为 null

getTestRunAttemptCount

public int getTestRunAttemptCount (String testRunName)

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

参数
testRunName String:{testRunStarted(String, int)} 提供的名称。

返回
int

getTestRunAttempts

public  getTestRunAttempts (String testRunName)

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

参数
testRunName String:{testRunStarted(String, int)} 提供的名称。

返回
给定测试运行的所有 TestRunResult,按尝试次数排序。

getTestRunForAttempts

public  getTestRunForAttempts (int attempt)

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

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

返回
给定尝试的所有 TestRunResult

getTestRunNames

public  getTestRunNames ()

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

这些测试运行可能已多次运行,并采用了不同的尝试。

返回

hasFailedTests

public boolean hasFailedTests ()

返回调用是否有任何失败的测试或假设失败的测试。

返回
boolean

hasTestRunResultsForName

public boolean hasTestRunResultsForName (String testRunName)

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

参数
testRunName String:{testRunStarted(String, int)} 提供的名称。

返回
boolean

invocationEnded

public void invocationEnded (long elapsedTime)

报告调用已终止,无论是成功终止还是因某种错误条件而终止。

将由 TradeFederation 框架自动调用。

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

invocationFailed

public void invocationFailed (Throwable cause)

由于某些错误条件,报告调用不完整。

将由 TradeFederation 框架自动调用。

参数
cause Throwable:失败的 Throwable 原因

invocationSkipped

public void invocationSkipped (SkipReason reason)

将调用报告为跳过

参数
reason SkipReason

invocationStarted

public void invocationStarted (IInvocationContext context)

报告测试调用的开始。

将由 TradeFederation 框架自动调用。报告程序需要替换此方法才能支持多设备报告。

参数
context IInvocationContext:调用相关信息

isDisabled

public boolean isDisabled ()

如果整个对象已停用(同时跳过设置和拆解),则返回 true。否则为 false。

返回
boolean

logAssociation

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,应与测试用例相关联。

setBuildInfo

public void setBuildInfo (IBuildInfo buildInfo)

此方法已废弃。
测试时不再需要。

设置 build 信息。应仅用于测试。

参数
buildInfo IBuildInfo

setDisable

public void setDisable (boolean isDisabled)

设置是否应停用对象。停用表示应跳过设置和拆解步骤。可用于在默认构造函数中默认停用对象。

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

setMergeStrategy

public void setMergeStrategy (MergeStrategy strategy)

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

参数
strategy MergeStrategy

testAssumptionFailure

public void testAssumptionFailure (TestDescription test, 
                String trace)

当原子测试标记为假的假设条件时调用

参数
test TestDescription:用于标识测试

trace String:失败的堆栈轨迹

testAssumptionFailure

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

当原子测试标记为假的假设条件时调用

参数
test TestDescription:用于标识测试

failure FailureDescription:描述失败及其上下文的 FailureDescription

testEnded

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)

testEnded

public void testEnded (TestDescription test, 
                 testMetrics)

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

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

参数
test TestDescription:用于标识测试

testMetrics :发出的指标的 ERROR(/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:用于标识测试

testModuleEnded

public void testModuleEnded ()

报告模块运行结束。

testModuleStarted

public void testModuleStarted (IInvocationContext moduleContext)

报告模块运行的开始时间。此回调与 testModuleEnded() 相关联,在序列中是可选的。它仅在使用模块(基于套件的运行程序)的运行期间使用。

参数
moduleContext IInvocationContext:模块的 IInvocationContext

testRunEnded

public void testRunEnded (long elapsedTime, 
                 runMetrics)

报告测试运行结束。

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

runMetrics :测试运行结束时报告的键值对

testRunFailed

public void testRunFailed (FailureDescription failure)

由于 FailureDescription 所述的失败,报告测试运行未能完成。

参数
failure FailureDescription:描述失败及其上下文的 FailureDescription

testRunFailed

public void testRunFailed (String errorMessage)

由于出现严重错误,报告测试运行未能完成。

参数
errorMessage StringString,用于说明运行失败的原因。

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)

报告测试运行的开始。

参数
name String:测试运行作业名称

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

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

testRunStopped

public void testRunStopped (long elapsedTime)

报告测试运行在完成之前因用户请求而停止。

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

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

testSkipped

public void testSkipped (TestDescription test, 
                SkipReason reason)

当测试因非预期原因而被跳过且未执行时调用。 系统会尝试重试这些测试,以便正确执行。

参数
test TestDescription:用于标识测试

reason SkipReasonSkipReason

testStarted

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

testStarted

public void testStarted (TestDescription test)

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

参数
test TestDescription:用于标识测试

受保护的方法

clearModuleLogFiles

protected final void clearModuleLogFiles ()

允许清理模块文件,以免长时间携带这些文件。

clearResultsForName

protected final void clearResultsForName (String testRunName)

用于清除指定运行名称的结果。仅应在某些情况下使用,例如结果汇总器。

参数
testRunName String

setIsAggregrateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切换“汇总指标”选项

参数
aggregate boolean