CollectingTestListener
public
class
CollectingTestListener
extends Object
implements
IDisableable,
ILogSaverListener,
ITestInvocationListener
| java.lang.Object | |
| ↳ | 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(TestStatus status)
返回相应运行中处于指定状态的测试数量。 |
int
|
getNumTestsInState(TestResult.TestStatus ddmlibStatus)
为了与旧版状态类型兼容 |
int
|
getNumTotalTests()
返回所有运行的完整测试总数。 |
IBuildInfo
|
getPrimaryBuildInfo()
返回通过 |
|
getRunResults()
此方法已弃用。
使用 |
TestRunResult
|
getTestRunAtAttempt(String testRunName, int attempt)
返回单次尝试的 |
int
|
getTestRunAttemptCount(String testRunName)
返回指定测试运行名称的尝试次数。 |
|
getTestRunAttempts(String testRunName)
获取给定测试运行的 |
|
getTestRunForAttempts(int attempt)
获取指定尝试的所有结果。 |
|
getTestRunNames()
返回所有测试运行的所有名称。 |
boolean
|
hasFailedTests()
如果调用有任何失败的测试或假设失败的测试,则返回 true。 |
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)
在某些情况下,日志必须与测试用例紧密关联,但无法在直接 |
void
|
setBuildInfo(IBuildInfo buildInfo)
此方法已弃用。 不再需要用于测试。 |
void
|
setDisable(boolean isDisabled)
设置是否应停用对象。 |
void
|
setMergeStrategy(MergeStrategy strategy)
设置合并结果时要使用的 |
void
|
testAssumptionFailure(TestDescription test, String trace)
当原子测试标记其假设的条件为 false 时调用 |
void
|
testAssumptionFailure(TestDescription test, FailureDescription failure)
当原子测试标记其假设的条件为 false 时调用 |
void
|
testEnded(TestDescription test, long endTime,
|
void
|
testEnded(TestDescription test,
报告单个测试用例的执行结束时间。 |
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,
报告测试运行结束。 |
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
|
testSkipped(TestDescription test, SkipReason reason)
当测试因通常不预期的原因而被跳过且未执行时调用。 |
void
|
testStarted(TestDescription test, long startTime)
|
void
|
testStarted(TestDescription test)
报告单个测试用例的开始。 |
受保护的方法 | |
|---|---|
final
void
|
clearModuleLogFiles()
允许清理模块文件,以免长时间携带这些文件。 |
final
void
|
clearResultsForName(String testRunName)
允许清除指定运行名称的结果。 |
final
void
|
clearTestRunResults()
允许清除所有测试运行结果,以免这些结果保留过长时间。 |
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
publicgetMergedTestRunResults ()
返回不同尝试的所有运行的合并结果集合。
如果存在多个结果,则会合并每次测试运行的结果,其中最新的测试结果会覆盖之前运行的测试结果。测试运行按尝试次数排序。
系统会根据 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 |
|
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
publicgetTestRunAttempts (String testRunName)
获取给定测试运行的 TestRunResult 的所有尝试。
| 参数 | |
|---|---|
testRunName |
String:{testRunStarted(String, int) 给定的名称。 |
| 返回 | |
|---|---|
|
给定测试运行的所有 TestRunResult,按尝试次数排序。 |
getTestRunForAttempts
publicgetTestRunForAttempts (int attempt)
获取指定尝试的所有结果。
| 参数 | |
|---|---|
attempt |
int:我们想要获取结果的尝试。 |
| 返回 | |
|---|---|
|
给定尝试的所有 TestRunResult。 |
getTestRunNames
publicgetTestRunNames ()
返回所有测试运行的所有名称。
这些测试运行可能已多次运行,并进行了不同的尝试。
| 返回 | |
|---|---|
|
|
hasFailedTests
public boolean hasFailedTests ()
如果调用有任何失败的测试或假设失败的测试,则返回 true。
| 返回 | |
|---|---|
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 原因 |
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)
当原子测试标记其假设的条件为 false 时调用
| 参数 | |
|---|---|
test |
TestDescription:用于标识测试 |
trace |
String:失败的堆栈轨迹 |
testAssumptionFailure
public void testAssumptionFailure (TestDescription test, FailureDescription failure)
当原子测试标记其假设的条件为 false 时调用
| 参数 | |
|---|---|
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 |
String:描述运行失败原因的 String。 |
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 |
SkipReason:SkipReason |
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 |
clearTestRunResults
protected final void clearTestRunResults ()
允许清除所有测试运行结果,以免这些结果保留过长时间。
setIsAggregrateMetrics
protected void setIsAggregrateMetrics (boolean aggregate)
切换“汇总指标”选项
| 参数 | |
|---|---|
aggregate |
boolean |