自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
创建结果报告程序
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页将介绍如何实现新的结果报告程序并针对测试对其进行配置的基础知识。
核心接口
为了在 Tradefed 中定义新的结果报告程序,一个类必须实现 ITestInvocationListener
接口,该接口允许接收和处理调用的不同阶段:
invocationStarted
invocationEnded
invocationFailed
结果报告程序还处理每个测试运行的不同阶段:
testRunStarted
testStarted
testFailed
或 testIgnored
testEnded
testRunFailed
testRunEnded
考虑到所有这些事件,结果报告程序主要有两种类型,其特点分别是:
报告最终完整结果的结果报告程序
当涉及到与接收结果的外部服务进行交互时,此类型是最常见的情况。此类报告程序只是接收并累积结果,然后在 invocationEnded
时将结果全部发送到结果端点。
建议此类报告程序扩展 CollectingTestListener
而不是基接口,以避免在 invocationEnded
之前重复实现结果的保存和存储。
报告部分结果的结果报告程序
当接收结果并立即将其推送到其他一些位置时,此类型通常用于结果的流式传输方法。例如,将结果记录到控制台的报告程序就属于此类型。
此类型特定于需要对事件进行哪种类型的处理,因此通常建议实现基接口。
XML 配置
对象标记为 result_reporter
。例如:
<result_reporter class="com.android.tradefed.result.ConsoleResultReporter">
<option name="suppress-passed-tests" value="true"/>
</result_reporter>
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Create a result reporter\n\nThis page describes the basics of how to implement a new result reporter and\nconfigure it for a test.\n\nCore interface\n--------------\n\nIn order to define a new result reporter in Tradefed, a class must implement\nthe\n[`ITestInvocationListener`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/invocation_interfaces/com/android/tradefed/result/ITestInvocationListener.java)\ninterface that allows receiving and handling different stages of the\ninvocation:\n\n- `invocationStarted`\n- `invocationEnded`\n- `invocationFailed`\n\nResult reporters also handle the different stages of each test run:\n\n- `testRunStarted`\n- `testStarted`\n- `testFailed` or `testIgnored`\n- `testEnded`\n- `testRunFailed`\n- `testRunEnded`\n\nGiven all these events, there are two main types of result reporters, those that:\n\n- Care only about reporting the final complete results.\n- Take action on partial results.\n\n### Result reporter that reports final complete results\n\nThis type is the most common case when it comes to interacting with an external\nservice that receives the results. The reporter simply receives and accumulates\nthe results and then sends them all on `invocationEnded` to the result end-point.\n\nWe recommend that those reporters extend `CollectingTestListener` instead\nof the base interface in order to avoid reimplementing saving and storing the\nresults until `invocationEnded`.\n\n### Result reporter that reports partial results\n\nThis type is usually used for a streaming approach of the results, when results\nare received and pushed to some other places right away. For example, a reporter\nthat logs the results to the console would be of this type.\n\nThis type is specific to which type of handling is required on the events,\nso implementing the base interface is usually the recommended way.\n\n### XML configuration\n\nThe object tag is `result_reporter`. For example: \n\n \u003cresult_reporter class=\"com.android.tradefed.result.ConsoleResultReporter\"\u003e\n \u003coption name=\"suppress-passed-tests\" value=\"true\"/\u003e\n \u003c/result_reporter\u003e"]]