BugreportCollector

public class BugreportCollector
extends Object implements ITestInvocationListener

java.lang.Object
   ↳ com.android.tradefed.result.BugreportCollector


一种传递 ITestInvocationListener,用于在发生可配置的事件时收集 bug 报告,然后在每次收集 bug 报告后对其子级调用 ITestInvocationListener.testLog

行为:(FIXME:完成此部分)

  • 在每次测试用例失败后进行捕获
  • 在每个测试用例之后捕获
  • 在每个失败的测试用例之后捕获
  • 拍摄

摘要

嵌套类

class BugreportCollector.Predicate

一个完整的谓词,用于描述何时捕获 bug 报告。 

interface BugreportCollector.SubPredicate

 

字段

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

一种预定义的谓词,会在每个失败的测试用例后触发

public static final BugreportCollector.Predicate AT_START

一种预定义的谓词,在首次调用开始时触发

公共构造函数

BugreportCollector(ITestInvocationListener listener, ITestDevice testDevice)

公共方法

void addPredicate(BugreportCollector.Predicate p)
void blockUntilIdle()

阻塞,直到收集器不再收集任何 bug 报告。

TestSummary getSummary()

允许 InvocationListener 返回摘要。

void invocationEnded(long elapsedTime)

报告调用已终止,无论是成功终止还是因某些错误情况而终止。

void invocationFailed(Throwable cause)

报告因某些错误情况而导致的不完整调用。

void invocationStarted(IInvocationContext context)

报告测试调用的开始。

void setAsynchronous(boolean asynchronous)

设置 bugreport 收集是否应在不同的线程中收集 bugreport (asynchronous = true),还是应阻塞调用方直到捕获到 bugreport (asynchronous = false)。

void setDescriptiveName(String name)

设置记录 bug 报告时要使用的描述性名称。

void setDeviceWaitTime(int waitTime)

设置等待设备变为在线状态的时间(以秒为单位),然后我们再尝试捕获 bug 报告。

void testAssumptionFailure(TestDescription test, String trace)

当原子测试标记其假设的条件为 false 时调用

void testEnded(TestDescription test, HashMap<String, MetricMeasurement.Metric> testMetrics)

报告单个测试用例的执行结束时间。

void testFailed(TestDescription test, String trace)

报告单个测试用例的失败情况。

void testIgnored(TestDescription test)

当测试不会运行时(通常是因为测试方法使用 org.junit.Ignore 注释进行了注释)调用。

void testLog(String dataName, LogDataType dataType, InputStreamSource dataStream)

提供测试调用中的相关日志或调试数据。

void testRunEnded(long elapsedTime, HashMap<String, MetricMeasurement.Metric> runMetrics)

报告测试运行结束。

void testRunFailed(String errorMessage)

由于出现严重错误,报告测试运行未能完成。

void testRunStarted(String runName, int testCount)

报告测试运行的开始。

void testRunStopped(long elapsedTime)

报告测试运行因用户请求而在完成前停止。

void testStarted(TestDescription test)

报告单个测试用例的开始。

字段

AFTER_FAILED_TESTCASES

public static final BugreportCollector.Predicate AFTER_FAILED_TESTCASES

一种预定义的谓词,会在每个失败的测试用例后触发

AT_START

public static final BugreportCollector.Predicate AT_START

一种预定义的谓词,在首次调用开始时触发

公共构造函数

BugreportCollector

public BugreportCollector (ITestInvocationListener listener, 
                ITestDevice testDevice)

参数
listener ITestInvocationListener

testDevice ITestDevice

公共方法

addPredicate

public void addPredicate (BugreportCollector.Predicate p)

参数
p BugreportCollector.Predicate

blockUntilIdle

public void blockUntilIdle ()

阻塞,直到收集器不再收集任何 bug 报告。如果收集器未主动收集 bug 报告,则立即返回

getSummary

public TestSummary getSummary ()

允许 InvocationListener 返回摘要。

返回
TestSummary 总结跑步活动的 TestSummary,或 null

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:有关调用的信息

setAsynchronous

public void setAsynchronous (boolean asynchronous)

设置 bugreport 收集是否应在不同的线程中收集 bugreport (asynchronous = true),还是阻塞调用方直到捕获到 bugreport (asynchronous = false)。

参数
asynchronous boolean

setDescriptiveName

public void setDescriptiveName (String name)

设置记录 bug 报告时要使用的描述性名称。如果 nullBugreportCollector 将回退到序列化导致收集 bug 报告的事件名称的默认行为。

参数
name String

setDeviceWaitTime

public void setDeviceWaitTime (int waitTime)

设置等待设备变为在线状态的时间(以秒为单位),然后我们再尝试捕获 bug 报告。如果为负值,则不执行检查。在此检查期间遇到的任何 DeviceNotAvailableException 都会被记录并忽略。

参数
waitTime int

testAssumptionFailure

public void testAssumptionFailure (TestDescription test, 
                String trace)

当原子测试标记其假设的条件为 false 时调用

参数
test TestDescription:标识测试

trace String:失败的堆栈轨迹

testEnded

public void testEnded (TestDescription test, 
                HashMap<String, MetricMeasurement.Metric> testMetrics)

报告单个测试用例的执行结束时间。

如果未调用 testFailed(TestDescription, FailureDescription),则此测试通过。还会返回测试用例执行期间可能发出的任何键值指标。

参数
test TestDescription:标识测试

testMetrics HashMap:所发出指标的 Map

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:标识测试

testLog

public void testLog (String dataName, 
                LogDataType dataType, 
                InputStreamSource dataStream)

提供测试调用中的相关日志或调试数据。

必须在 ERROR(ITestInvocationListener.invocationFailed(Throwable)/ITestInvocationListener#invocationFailed(java.lang.Throwable) ITestInvocationListener.invocationFailed(Throwable))ERROR(/ITestInvocationListener#invocationEnded(long)) 之前调用

TradeFederation 框架会自动调用此方法,并提供主机日志和设备 logcat(如果适用)。

参数
dataName String:数据的描述性名称。例如“device_logcat”。String注意:dataName 在每次调用时可能不是唯一的。也就是说,实现者必须能够处理具有相同 dataName 的多次调用

dataType LogDataType:数据的 LogDataType

dataStream InputStreamSource:数据的 InputStreamSource。实现者应调用 createInputStream 开始读取数据,并确保在完成后关闭生成的 InputStream。调用方应确保数据源在 testLog 方法完成之前保持存在且可访问。

testRunEnded

public void testRunEnded (long elapsedTime, 
                HashMap<String, MetricMeasurement.Metric> runMetrics)

报告测试运行结束。FIXME:我们不能有两个具有不同类型的 Map<> 接口,因此我们必须在此处使用 HashMap。

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

runMetrics HashMap:在测试运行结束时通过 Metric 报告的键值对。

testRunFailed

public void testRunFailed (String errorMessage)

由于出现严重错误,报告测试运行未能完成。

参数
errorMessage StringString,用于描述运行失败的原因。

testRunStarted

public void testRunStarted (String runName, 
                int testCount)

报告测试运行的开始。

参数
runName String:测试运行名称

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

testRunStopped

public void testRunStopped (long elapsedTime)

报告测试运行因用户请求而在完成前停止。

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

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

testStarted

public void testStarted (TestDescription test)

报告单个测试用例的开始。旧版接口,应尽可能使用 testStarted(TestDescription)

参数
test TestDescription:标识测试