收集测试监听器

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 (TestResult.TestStatus status)

返回此运行的给定状态下的测试数。

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

getMergedTestRunResults

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 >

getNonAssociatedLogFiles

public MultiMap<String, LogFile> getNonAssociatedLogFiles ()

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

退货
MultiMap <String, LogFile >

getNumAllFailedTestRuns

public int getNumAllFailedTestRuns ()

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

退货
int

getNumAllFailedTests

public int getNumAllFailedTests ()

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

退货
int

getNumTestsInState

public int getNumTestsInState (TestResult.TestStatus status)

返回此运行的给定状态下的测试数。

参数
status TestResult.TestStatus

退货
int

getNumTotalTests

public int getNumTotalTests ()

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

退货
int

getPrimaryBuildInfo

public IBuildInfo getPrimaryBuildInfo ()

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

退货
IBuildInfo

获取运行结果

public  getRunResults ()

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

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

退货

getTestRunAtAttempt

public TestRunResult getTestRunAtAttempt (String testRunName, 
                int attempt)

返回一次尝试的TestRunResult

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

attempt int :尝试 ID。

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

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

获取测试运行名称

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 : 失败的ERROR(/Throwable)原因

调用开始

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)

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

参数
test TestDescription :标识测试

trace String :失败的堆栈跟踪

测试假设失败

public void testAssumptionFailure (TestDescription test, 
                FailureDescription failure)

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

参数
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 :测试结束的时间,通过ERROR(/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 : ERROR(/String)描述运行失败的原因。

测试运行开始

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

报告测试运行的开始。

参数
name String : 测试运行名称

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

attemptNumber int : order number,标识同一 runName 多次运行的不同尝试。 attemptNumber 是从 0 开始索引的,每次发生新的运行时都应该递增。例如,一个测试被精细地重试了 3 次,它应该在同一个 runName 下总共运行 4 次,并且 attemptNumber 是从 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 : order number,标识同一 runName 多次运行的不同尝试。 attemptNumber 是从 0 开始索引的,每次发生新的运行时都应该递增。例如,一个测试被精细地重试了 3 次,它应该在同一个 runName 下总共运行 4 次,并且 attemptNumber 是从 0 到 3。

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

测试运行已停止

public void testRunStopped (long elapsedTime)

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

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

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

测试开始

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 :测试开始的时间,通过ERROR(/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

setIsAggregrateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切换“聚合指标”选项

参数
aggregate boolean