收集测试监听器

public class CollectingTestListener
extends Object implements ITestInvocationListener, ILogSaverListener

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)

void logAssociation (String dataName, LogFile logFile)

void setBuildInfo (IBuildInfo buildInfo)

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

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)

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)
void testModuleEnded ()
void testModuleStarted (IInvocationContext moduleContext)
void testRunEnded (long elapsedTime, runMetrics) testRunEnded (long elapsedTime, runMetrics)

void testRunFailed (FailureDescription failure)

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)

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

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

参数
status 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)

参数
elapsedTime long

调用失败

public void invocationFailed (Throwable cause)

参数
cause Throwable

调用开始

public void invocationStarted (IInvocationContext context)

参数
context IInvocationContext

日志关联

public void logAssociation (String dataName, 
                LogFile logFile)

参数
dataName String

logFile LogFile

设置构建信息

public void setBuildInfo (IBuildInfo buildInfo)

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

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

参数
buildInfo IBuildInfo

设置合并策略

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

测试结束

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

参数
test TestDescription

endTime long

testMetrics

测试结束

public void testEnded (TestDescription test, 
                 testMetrics)

参数
test TestDescription

testMetrics

测试失败

public void testFailed (TestDescription test, 
                FailureDescription failure)

参数
test TestDescription

failure FailureDescription

测试失败

public void testFailed (TestDescription test, 
                String trace)

参数
test TestDescription

trace String

测试被忽略

public void testIgnored (TestDescription test)

参数
test TestDescription

测试模块结束

public void testModuleEnded ()

测试模块启动

public void testModuleStarted (IInvocationContext moduleContext)

参数
moduleContext IInvocationContext

测试运行结束

public void testRunEnded (long elapsedTime, 
                 runMetrics)

参数
elapsedTime long

runMetrics

测试运行失败

public void testRunFailed (FailureDescription failure)

参数
failure FailureDescription

测试运行失败

public void testRunFailed (String errorMessage)

参数
errorMessage String

测试运行开始

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

参数
name String

numTests int

attemptNumber int

测试运行开始

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

startTime long

测试运行停止

public void testRunStopped (long elapsedTime)

参数
elapsedTime long

测试开始

public void testStarted (TestDescription test, 
                long startTime)

参数
test TestDescription

startTime long

测试开始

public void testStarted (TestDescription test)

参数
test TestDescription

受保护的方法

清除模块日志文件

protected final void clearModuleLogFiles ()

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

清除名称结果

protected final void clearResultsForName (String testRunName)

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

参数
testRunName String

setIsAggregateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切换“聚合指标”选项

参数
aggregate boolean