错误报告收集器
public class BugreportCollector
extends Object
implements ITestInvocationListener
java.lang.Object | |
↳ | com.android.tradefed.result.BugreportCollector |
一个传递ITestInvocationListener
,它在可配置事件发生时收集错误报告,然后在收集每个错误报告后在其子级上调用ITestInvocationListener#testLog
。
- 在每个测试用例失败后捕获
- 每个测试用例后捕获
- 在每个失败的测试用例后捕获
- 捕获
概括
嵌套类 | |
---|---|
class | BugreportCollector.Predicate 描述何时捕获错误报告的完整谓词。 |
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 () 阻塞直到收集器不再收集任何错误报告。 |
TestSummary | getSummary () 允许 IncationListener 返回摘要。 |
void | invocationEnded (long elapsedTime) 报告调用已终止,无论是成功还是由于某些错误情况。 |
void | invocationFailed (Throwable cause) 由于某些错误情况而报告不完整的调用。 |
void | invocationStarted ( IInvocationContext context) 报告测试调用的开始。 |
void | setAsynchronous (boolean asynchronous) 设置错误报告收集是否应在不同线程中收集错误报告 ( |
void | setDescriptiveName (String name) 设置记录错误报告时使用的描述性名称。 |
void | setDeviceWaitTime (int waitTime) 设置在尝试捕获错误报告之前等待设备上线的时间(以秒为单位)。 |
void | testAssumptionFailure ( TestDescription test, String trace) 当原子测试标记其假定条件为 false 时调用 |
void | testEnded ( TestDescription test, testMetrics) testEnded ( TestDescription test, 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, runMetrics) testRunEnded (long elapsedTime, 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
在每个失败的测试用例后触发的预定义谓词
公共构造函数
错误报告收集器
public BugreportCollector (ITestInvocationListener listener, ITestDevice testDevice)
参数 | |
---|---|
listener | ITestInvocationListener |
testDevice | ITestDevice |
公共方法
阻塞直到空闲
public void blockUntilIdle ()
阻塞直到收集器不再收集任何错误报告。如果收集器没有主动收集错误报告,请立即返回
调用结束
public void invocationEnded (long elapsedTime)
报告调用已终止,无论是成功还是由于某些错误情况。
将由 TradeFederation 框架自动调用。参数 | |
---|---|
elapsedTime | long :调用所用的时间(以毫秒为单位) |
调用失败
public void invocationFailed (Throwable cause)
由于某些错误情况而报告不完整的调用。
将由 TradeFederation 框架自动调用。参数 | |
---|---|
cause | Throwable :失败的Throwable 原因 |
调用开始
public void invocationStarted (IInvocationContext context)
报告测试调用的开始。
将由 TradeFederation 框架自动调用。记者需要重写此方法以支持多设备报告。
参数 | |
---|---|
context | IInvocationContext :有关调用的信息 |
设置异步
public void setAsynchronous (boolean asynchronous)
设置错误报告收集是否应在不同线程中收集错误报告 ( asynchronous = true
),或阻止调用者直到捕获错误报告 ( asynchronous = false
)。
参数 | |
---|---|
asynchronous | boolean |
设置描述性名称
public void setDescriptiveName (String name)
设置记录错误报告时使用的描述性名称。如果为null
, BugreportCollector
将回退到序列化导致收集错误报告的事件名称的默认行为。
参数 | |
---|---|
name | String |
设置设备等待时间
public void setDeviceWaitTime (int waitTime)
设置在尝试捕获错误报告之前等待设备上线的时间(以秒为单位)。如果是否定的,则不会执行任何检查。在此检查期间遇到的任何DeviceNotAvailableException
将被记录并忽略。
参数 | |
---|---|
waitTime | int |
测试假设失败
public void testAssumptionFailure (TestDescription test, String trace)
当原子测试标记其假定条件为 false 时调用
参数 | |
---|---|
test | TestDescription :标识测试 |
trace | String : 失败的堆栈跟踪 |
测试结束
public void testEnded (TestDescription test,testMetrics)
报告单个测试用例的执行结束。
如果未调用testFailed(TestDescription, FailureDescription)
,则此测试通过。还返回测试用例执行期间可能发出的任何键/值指标。
参数 | |
---|---|
test | TestDescription :标识测试 |
testMetrics | ERROR(/Map) |
测试失败
public void testFailed (TestDescription test, String trace)
报告单个测试用例的失败。
将在 testStarted 和 testEnded 之间调用。
参数 | |
---|---|
test | TestDescription :标识测试 |
trace | String : 失败的堆栈跟踪 |
测试被忽略
public void testIgnored (TestDescription test)
当测试不会运行时调用,通常是因为测试方法用 org.junit.Ignore 注解。
参数 | |
---|---|
test | TestDescription :标识测试 |
测试日志
public void testLog (String dataName, LogDataType dataType, InputStreamSource dataStream)
提供来自测试调用的关联日志或调试数据。
必须在ERROR(/ITestInvocationListener#invocationFailed(Throwable))
或ERROR(/ITestInvocationListener#invocationEnded(long))
之前调用TradeFederation 框架将自动调用此方法,提供主机日志和设备 logcat(如果适用)。参数 | |
---|---|
dataName | String :数据的String 描述性名称。例如“device_logcat”。注意 每次调用时 dataName 可能不是唯一的。即实现者必须能够处理具有相同 dataName 的多个调用 |
dataType | LogDataType :数据的LogDataType |
dataStream | InputStreamSource :数据的InputStreamSource 。实现者应该调用 createInputStream 来开始读取数据,并确保完成后关闭生成的 InputStream。调用者应确保数据源保持存在且可访问,直到 testLog 方法完成。 |
测试运行结束
public void testRunEnded (long elapsedTime,runMetrics)
报告测试运行结束。 FIXME:我们不能有两个不同类型的 Map<> 接口,所以我们必须在这里使用 HashMap。
参数 | |
---|---|
elapsedTime | long :设备报告的经过时间,以毫秒为单位 |
runMetrics | Metric 测试运行结束时报告的键值对。 |
测试运行失败
public void testRunFailed (String errorMessage)
报告测试运行由于致命错误而未能完成。
参数 | |
---|---|
errorMessage | String :描述运行失败原因的String 。 |
测试运行开始
public void testRunStarted (String runName, int testCount)
报告测试运行的开始。
参数 | |
---|---|
runName | String : 测试运行名称 |
testCount | int : 测试运行中的测试总数 |
测试运行停止
public void testRunStopped (long elapsedTime)
由于用户请求,报告测试运行在完成之前停止。
TODO:当前未使用,考虑删除
参数 | |
---|---|
elapsedTime | long :设备报告的经过时间,以毫秒为单位 |
测试开始
public void testStarted (TestDescription test)
报告单个测试用例的开始。较旧的接口,应尽可能使用testStarted(com.android.tradefed.result.TestDescription)
。
参数 | |
---|---|
test | TestDescription :标识测试 |
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2023-12-01。