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.
Cấu trúc của trình chạy kiểm thử
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.
Trình chạy kiểm thử là đơn vị thực thi của luồng gọi. Đây là nơi các chương trình kiểm thử thực sự chạy.
Giao diện
Trình chạy kiểm thử được xác định thông qua giao diện IRemoteTest. Giao diện này cung cấp một phương thức run
đơn giản để triển khai sẽ được gọi khi chạy kiểm thử.
Điều này cho phép định nghĩa đơn giản nhất về một lần chạy kiểm thử. Tuy nhiên, trong thực tế, người viết mã kiểm thử sẽ cần thêm thông tin để viết mã kiểm thử đúng cách, thường là thông tin về bản dựng và thiết bị. Đây là lúc các giao diện sau đây phát huy tác dụng.
Cơ bản
Hai giao diện này được sử dụng rộng rãi nhất hiện nay, vì chúng đại diện cho nhu cầu cơ bản của hầu hết các bài kiểm thử.
- IBuildReceiver cho phép kiểm thử lấy đối tượng
IBuildInfo
được tạo ở bước trình cung cấp bản dựng chứa tất cả thông tin và cấu phần phần mềm liên quan đến việc thiết lập kiểm thử.
- IDeviceTest cho phép TF nhận đối tượng
ITestDevice
đại diện cho thiết bị đang được kiểm thử và cung cấp API để tương tác với thiết bị đó.
Nâng cao
Có các giao diện bổ sung cho phép tương tác phức tạp hơn giữa bộ kiểm thử và trình chạy kiểm thử:
- ITestFilterReceiver, cho phép kiểm thử nhận một bộ lọc để chỉ chạy một số kiểm thử nhất định. Điều này rất hữu ích khi chạy một tập hợp con kiểm thử.
- ITestCollector, cho phép trình chạy kiểm thử chỉ chạy thử các kiểm thử thay vì thực sự thực thi các kiểm thử đó. Điều này rất hữu ích trong việc thu thập danh sách tất cả các trường hợp kiểm thử.
Trình chạy kiểm thử hiện có
Hiện đã có nhiều trình chạy kiểm thử, một số trình chạy kiểm thử cho các loại kiểm thử chính:
Ngoài những trình chạy kiểm thử tuỳ chỉnh nêu trên, còn có một số lượng lớn trình chạy kiểm thử tuỳ chỉnh khác; các trình chạy này phục vụ các mục đích chuyên biệt cho một số hoạt động kiểm thử chức năng, ví dụ: Kiểm thử khởi động.
Viết trình chạy kiểm thử mới
Bạn có thể xem thêm hướng dẫn về cách viết trình chạy kiểm thử mới trong phần viết mã kiểm thử.
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,["# Structure of a test runner\n\nThe test runner is the execution unit of the invocation flow. This is where\ntests actually run.\n\nInterfaces\n----------\n\nTest runners are defined via the [IRemoteTest\ninterface](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/invocation_interfaces/com/android/tradefed/testtype/IRemoteTest.java),\nwhich provides a simple `run` method to implement that will be called when the\ntests is to run.\n\nThis allows the simplest definition of a test run to occur. But in practice,\ntest writers will need more information to properly write their tests, typically\nbuild and device information. This is where the following interfaces come handy.\n\n### Basic\n\nThese two interfaces are the most widely used today, as they represent the basic\nneeds of most tests.\n\n- [IBuildReceiver](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/IBuildReceiver.java) allows the test to get the `IBuildInfo` object created at the [build\n provider](/docs/core/tests/tradefed/architecture/build-provider) step containing all the information and artifacts related to the test setup.\n- [IDeviceTest](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/IDeviceTest.java) allows TF to receive the `ITestDevice` object that represents the device under test and provides an API to interact with it.\n\n### Advanced\n\nThere are additional interfaces that allow more complex interaction between the\ntest harness and the test runner:\n\n- [ITestFilterReceiver](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/ITestFilterReceiver.java), which allows the test to receive a set of filters for running certain tests only. This is useful in running a subset of the tests.\n- [ITestCollector](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/testtype/ITestCollector.java), which allows a test runner to only dry-run the tests instead of actually executing them. This is useful in collecting the list of all test cases.\n\nExisting test runners\n---------------------\n\nA variety of test runners already exists, some for major test types:\n\n- [AndroidJUnitTest / InstrumentationTest](/reference/tradefed/com/android/tradefed/testtype/AndroidJUnitTest) (associated with AJUR on the device side)\n- [GTest](/reference/tradefed/com/android/tradefed/testtype/GTest) (device and host side) with [googletest library](https://github.com/google/googletest)\n- [Host-driven\n tests](/reference/tradefed/com/android/tradefed/testtype/HostTest) (Java tests that execute on the host and call the device from there)\n- [Pure Java unit\n tests](/reference/tradefed/com/android/tradefed/testtype/HostTest) (our runner does both)\n- [Python tests](/reference/tradefed/com/android/tradefed/testtype/python/PythonBinaryHostTest)\n- [Google Benchmark\n tests](/reference/tradefed/com/android/tradefed/testtype/GoogleBenchmarkTest) with [benchmark library](https://github.com/google/benchmark)\n\nA large number of custom test runners exist besides the above; they serve\nspecialized purposes for some functional testing, for example Boot Test.\n\nWrite a new test runner\n-----------------------\n\nMore guidance of writing a new test runner is available in the [writing tests\nsection](/docs/core/tests/tradefed/testing/through-tf/new-test-runner)."]]