Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Tạo trình báo cáo kết quả
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này mô tả các kiến thức cơ bản về cách triển khai trình báo cáo kết quả mới và định cấu hình trình báo cáo đó cho một kiểm thử.
Giao diện chính
Để xác định trình báo cáo kết quả mới trong Tradefed, một lớp phải triển khai giao diện ITestInvocationListener
cho phép nhận và xử lý các giai đoạn khác nhau của lệnh gọi:
invocationStarted
invocationEnded
invocationFailed
Trình báo cáo kết quả cũng xử lý các giai đoạn khác nhau của mỗi lần chạy kiểm thử:
testRunStarted
testStarted
testFailed
hoặc testIgnored
testEnded
testRunFailed
testRunEnded
Với tất cả các sự kiện này, có hai loại trình báo cáo kết quả chính, đó là:
- Chỉ quan tâm đến việc báo cáo kết quả hoàn chỉnh cuối cùng.
- Xử lý một phần kết quả.
Trình báo cáo kết quả báo cáo kết quả hoàn chỉnh cuối cùng
Loại này là trường hợp phổ biến nhất khi tương tác với một dịch vụ bên ngoài nhận kết quả. Trình báo cáo chỉ cần nhận và tích luỹ kết quả, sau đó gửi tất cả kết quả đó trên invocationEnded
đến điểm cuối kết quả.
Bạn nên mở rộng CollectingTestListener
thay vì giao diện cơ sở để tránh triển khai lại việc lưu và lưu trữ kết quả cho đến invocationEnded
.
Trình báo cáo kết quả báo cáo một phần kết quả
Loại này thường được dùng cho phương pháp truyền trực tuyến kết quả, khi kết quả được nhận và đẩy ngay đến một số nơi khác. Ví dụ: một trình báo cáo ghi nhật ký kết quả vào bảng điều khiển sẽ thuộc loại này.
Loại này dành riêng cho loại xử lý bắt buộc trên các sự kiện, vì vậy, bạn nên triển khai giao diện cơ sở.
Cấu hình XML
Thẻ đối tượng là result_reporter
. Ví dụ:
<result_reporter class="com.android.tradefed.result.ConsoleResultReporter">
<option name="suppress-passed-tests" value="true"/>
</result_reporter>
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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"]]