CollectingTestListener

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) 报告的主要 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 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)

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

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)

切换“汇总指标”选项

公共构造函数

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

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

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

参数
elapsedTime long

invocationFailed

public void invocationFailed (Throwable cause)

参数
cause Throwable

invocationStarted

public void invocationStarted (IInvocationContext context)

参数
context IInvocationContext

logAssociation

public void logAssociation (String dataName, 
                LogFile logFile)

参数
dataName String

logFile LogFile

setBuildInfo

public void setBuildInfo (IBuildInfo buildInfo)

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

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

参数
buildInfo IBuildInfo

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

testEnded

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

参数
test TestDescription

endTime long

testMetrics

testEnded

public void testEnded (TestDescription test, 
                 testMetrics)

参数
test TestDescription

testMetrics

testFailed

public void testFailed (TestDescription test, 
                FailureDescription failure)

参数
test TestDescription

failure FailureDescription

testFailed

public void testFailed (TestDescription test, 
                String trace)

参数
test TestDescription

trace String

testIgnored

public void testIgnored (TestDescription test)

参数
test TestDescription

testModuleEnded

public void testModuleEnded ()

testModuleStarted

public void testModuleStarted (IInvocationContext moduleContext)

参数
moduleContext IInvocationContext

testRunEnded

public void testRunEnded (long elapsedTime, 
                 runMetrics)

参数
elapsedTime long

runMetrics

testRunFailed

public void testRunFailed (FailureDescription failure)

参数
failure FailureDescription

testRunFailed

public void testRunFailed (String errorMessage)

参数
errorMessage String

testRunStarted

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

参数
name String

numTests int

attemptNumber int

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

startTime long

testRunStopped

public void testRunStopped (long elapsedTime)

参数
elapsedTime long

testStarted

public void testStarted (TestDescription test, 
                long startTime)

参数
test TestDescription

startTime long

testStarted

public void testStarted (TestDescription test)

参数
test TestDescription

受保护的方法

clearModuleLogFiles

protected final void clearModuleLogFiles ()

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

clearResultsForName

protected final void clearResultsForName (String testRunName)

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

参数
testRunName String

setIsAggregrateMetrics

protected void setIsAggregrateMetrics (boolean aggregate)

切换“汇总指标”选项

参数
aggregate boolean