收集测试监听器
public class CollectingTestListener
extends Object
implements ITestInvocationListener, ILogSaverListener
对象 | |
↳ | com.android.tradefed.result.CollectingTestListener |
一个ITestInvocationListener
将收集所有的测试结果。
虽然在此对象使用的数据结构是线程安全的, ITestInvocationListener
回调必须以正确的顺序被调用。
概括
公共构造函数 | |
---|---|
CollectingTestListener () |
公共方法 | |
---|---|
IBuildInfo | getBuildInfo () 此方法已弃用。依靠 |
TestRunResult | getCurrentRunResults () 获取当前测试运行的结果。 |
int | getExpectedTests () 返回预期测试计数的数量。 |
IInvocationContext | getInvocationContext () 返回已通过报道调用上下文 |
getMergedTestRunResults () 返回不同尝试中所有运行的合并结果集合。 | |
IInvocationContext | getModuleContextForRunResult (String testRunName) 返回 |
MultiMap<String, LogFile> | getModuleLogFiles () 返回包含与模块关联的所有记录文件的地图副本 |
MultiMap<String, LogFile> | getNonAssociatedLogFiles () 返回包含与测试运行或模块无关的所有记录文件的映射副本。 |
int | getNumAllFailedTestRuns () 返回处于失败状态的测试运行总数 |
int | getNumAllFailedTests () 返回处于失败状态的测试总数(仅失败,假设失败不计入)。 |
int | getNumTestsInState (TestResult.TestStatus status) 返回此运行在给定状态下的测试数量。 |
int | getNumTotalTests () 返回所有运行的完整测试总数。 |
IBuildInfo | getPrimaryBuildInfo () 返回已通过报告的主要构建信息 |
getRunResults () 此方法已弃用。使用 | |
TestRunResult | getTestRunAtAttempt (String testRunName, int attempt) 返回 |
int | getTestRunAttemptCount (String testRunName) 返回给定测试运行名称的尝试次数。 |
getTestRunAttempts (String testRunName) 获取的所有尝试 | |
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) 设置 |
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 ()
此方法已弃用。
依靠IBuildInfo
从getInvocationContext()
返回构建信息。
退货 | |
---|---|
IBuildInfo |
获取当前运行结果
public TestRunResult getCurrentRunResults ()
获取当前测试运行的结果。
请注意,结果可能不完整。它建议测试的值TestRunResult.isRunComplete()
处理结果之前和/或(@link TestRunResult#isRunFailure()}为适当。
退货 | |
---|---|
TestRunResult | 在TestRunResult 最后一次测试期间收集的数据代表 |
获取调用上下文
public IInvocationContext getInvocationContext ()
返回已通过报道调用上下文invocationStarted(com.android.tradefed.invoker.IInvocationContext)
退货 | |
---|---|
IInvocationContext |
获取合并测试运行结果
publicgetMergedTestRunResults ()
返回不同尝试中所有运行的合并结果集合。
如果有多个结果,则合并每次测试运行,最新的测试结果覆盖之前运行的测试结果。测试运行按尝试次数排序。
对于相同的尝试指标将基于偏好设定合并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 |
getNumAllFailedTests
public int getNumAllFailedTests ()
返回处于失败状态的测试总数(仅失败,假设失败不计入)。
退货 | |
---|---|
int |
getNumTestsInState
public int getNumTestsInState (TestResult.TestStatus status)
返回此运行在给定状态下的测试数量。
参数 | |
---|---|
status | TestResult.TestStatus |
退货 | |
---|---|
int |
getNumTotalTests
public int getNumTotalTests ()
返回所有运行的完整测试总数。
退货 | |
---|---|
int |
获取主要构建信息
public IBuildInfo getPrimaryBuildInfo ()
返回已通过报告的主要构建信息invocationStarted(com.android.tradefed.invoker.IInvocationContext)
主构建是由运行配置的第一个构建提供程序返回的构建。如果没有上下文(没有构建到测试用例),则返回 null。
退货 | |
---|---|
IBuildInfo |
获取测试运行尝试
public TestRunResult getTestRunAtAttempt (String testRunName, int attempt)
返回TestRunResult
的一次尝试。
参数 | |
---|---|
testRunName | String :由{给出的名称testRunStarted(String, int) 。 |
attempt | int :企图ID。 |
退货 | |
---|---|
TestRunResult | 该TestRunResult 对于给定的名称和尝试ID或null ,如果它不存在。 |
获取测试运行尝试计数
public int getTestRunAttemptCount (String testRunName)
返回给定测试运行名称的尝试次数。
参数 | |
---|---|
testRunName | String :由{给出的名称testRunStarted(String, int) 。 |
退货 | |
---|---|
int |
获取测试运行尝试
publicgetTestRunAttempts (String testRunName)
获取的所有尝试TestRunResult
给定的测试运行。
参数 | |
---|---|
testRunName | String :由{给出的名称testRunStarted(String, int) 。 |
退货 | |
---|---|
所有TestRunResult 对于给定的试运行,下令尝试。 |
getTestRunForAttempts
publicgetTestRunForAttempts (int attempt)
获取给定尝试的所有结果。
参数 | |
---|---|
attempt | int :我们想要的结果的企图。 |
退货 | |
---|---|
所有TestRunResult 对于一个给定的尝试。 |
获取测试运行名称
publicgetTestRunNames ()
返回所有测试运行的所有名称。
这些测试运行可能以不同的尝试运行了多次。
退货 | |
---|---|
测试失败
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 |
setIsAggregrateMetrics
protected void setIsAggregrateMetrics (boolean aggregate)
切换“聚合指标”选项
参数 | |
---|---|
aggregate | boolean |