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.
Chạy kiểm thử tự động (Android 11 trở lên)
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.
Có hai cách để chạy kiểm thử tự động CTS:
Trade Federation là một ứng dụng và khung kiểm thử cho phép bạn chạy kiểm thử qua dòng lệnh. Về cơ bản, khung này cho phép bạn chú thích các bài kiểm thử bằng chú thích @Test
và ứng dụng sẽ tìm và chạy các bài kiểm thử đó.
OmniLab Android Test Station là một ứng dụng cho phép bạn chạy các chương trình kiểm thử trong GUI.
Trang này giải thích cách chạy kiểm thử tự động bằng Trade Federation. Để biết hướng dẫn về cách chạy kiểm thử bằng Bộ kiểm thử Android OmniLab, hãy xem phần Trạm kiểm thử Android OmniLab.
Chạy tất cả các bài kiểm thử CTS tự động
Trade Federation chứa bảng điều khiển CTS, một giao diện dòng lệnh để chạy kiểm thử. Cách chạy toàn bộ bộ kiểm thử CTS tự động:
- Đảm bảo bạn đã làm theo hướng dẫn trong bài viết Thiết lập tính năng kiểm thử tự động CTS.
Trên máy trạm kiểm thử, hãy chạy bảng điều khiển CTS bằng cách chạy tập lệnh cts-tradefed
từ thư mục đã giải nén gói CTS:
./android-cts/tools/cts-tradefed
Bảng điều khiển CTS hiển thị một con trỏ để bạn nhập các lệnh CTS (cts-tradefed >
).
Kế hoạch kiểm thử cts
chứa tất cả các kiểm thử CTS tự động. Thực thi lệnh sau để chạy kế hoạch kiểm thử cts
:
run cts
Các kiểm thử CTS tự động sẽ thực thi. Xin lưu ý những điều sau:
Android 13 trở lên hỗ trợ kiểm thử trên nhiều thiết bị. Các kiểm thử này chỉ chạy tự động khi bạn sử dụng tính năng phân đoạn. Để biết thêm thông tin về việc phân đoạn, hãy xem phần Cải thiện thời gian thực thi kiểm thử. Nếu bạn muốn chạy các chương trình kiểm thử này theo cách thủ công, hãy xem phần Chạy chương trình kiểm thử trên nhiều thiết bị.
Bất cứ khi nào chạy CTS, hãy nhấn tổ hợp phím ctrl+c để dừng bảng điều khiển CTS hiện có rồi chạy lại bảng điều khiển CTS.
Bạn không thể chạy nhiều phiên bản CTS trên một máy chủ lưu trữ vì mỗi phiên bản sẽ mở bằng một máy chủ mã vị trí mở (OLC) hiện có.
Xem kết quả kiểm thử. Để biết thêm thông tin, hãy xem phần Diễn giải kết quả CTS.
Nếu đây là lần chạy kiểm thử đầu tiên, thì có thể có một số kiểm thử không thành công do các vấn đề nằm ngoài tầm kiểm soát của bạn. Ví dụ: kết nối mạng có thể chậm hoặc tín hiệu GPS có thể yếu. Chạy lại (thử lại) các chương trình kiểm thử cho đến khi tất cả mô-đun kiểm thử hoàn tất và số lần kiểm thử không thành công giống nhau giữa hai phiên thử lại gần đây nhất:
run retry --retry session_number`
Sau khi các lần kiểm thử không thành công đều nhất quán trong các lần thử lại, hãy tập trung gỡ lỗi các lần kiểm thử không thành công còn lại. Để biết thông tin về cách khắc phục sự cố liên quan đến kết quả kiểm thử, hãy xem phần Phân loại các lỗi kiểm thử và Khắc phục sự cố kiểm thử CTS.
Chạy CTS cho thiết bị nhiều màn hình
Nếu thiết bị của bạn đang chạy Android 11 hoặc 12 và có nhiều màn hình, bạn phải chạy riêng kế hoạch kiểm thử cts-foldable
:
run cts-foldable
Các trường hợp kiểm thử đã vượt qua hoặc không vượt qua cho chế độ màn hình thay thế được thêm vào bằng giá trị từ display_mode
, ví dụ: testcase1[display_mode=0]
.
Chạy kiểm thử trên nhiều thiết bị (Android 15 trở xuống)
Thực thi lệnh sau để chạy kế hoạch kiểm thử cts-multidevice
:
run cts-multidevice
Chạy các kế hoạch kiểm thử riêng lẻ
Thay vì chạy tất cả kế hoạch kiểm thử cùng một lúc, bạn có thể chạy từng kế hoạch kiểm thử. Tuỳ chọn này hữu ích để tiết kiệm thời gian và tập trung vào một nhóm kiểm thử cụ thể.
Cách chạy một kế hoạch kiểm thử riêng lẻ:
Xác định tên của kế hoạch kiểm thử mà bạn muốn chạy bằng cách thực thi lệnh list modules
.
Chạy kế hoạch kiểm thử:
run cts --plan test_module_or_plan_name
Cải thiện thời gian thực thi kiểm thử
Nếu muốn cải thiện thời gian thực thi kiểm thử, bạn có thể phân đoạn kiểm thử trên nhiều thiết bị. Tính năng phân đoạn yêu cầu máy chủ lưu trữ kết nối ít nhất hai thiết bị, nhưng bạn nên kết nối 6 thiết bị trở lên để đạt được hiệu quả cao.
Để phân đoạn kiểm thử trên Android 11 trở lên, hãy chạy:
run cts --shard-count number_of_shards
Ngoài ra, trước khi chạy kiểm thử để xác thực, bạn có thể cải thiện thời gian thực thi kiểm thử bằng cách sử dụng lệnh run cts-dev
của CTS. Lệnh này bỏ qua các điều kiện tiên quyết, tính năng thu thập thông tin thiết bị và tất cả trình kiểm tra trạng thái hệ thống.
Công cụ này cũng chỉ chạy các bài kiểm thử trên một ABI duy nhất.
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-30 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-30 UTC."],[],[],null,["# Run automated tests (Android 11 or higher)\n\nThere are two options for running CTS automated tests:\n\n- *Trade Federation* is an app and test framework that lets you\n run tests from the command line. Fundamentally, the framework\n lets you annotate tests using the `@Test` annotation and the app finds and runs\n those tests.\n\n- *OmniLab Android Test Station* is an app that lets you run tests\n in a GUI.\n\nThis page explains how to run automated tests using Trade Federation. For\ninstructions on running tests using OmniLab Android Test Harness, see\n[OmniLab Android Test Station](/docs/core/tests/development/android-test-station/ats-user-guide).\n\nRun all automated CTS tests\n---------------------------\n\nTrade Federation contains the *CTS console*, a command-line interface for\nrunning tests. To run the entire automated CTS test suite:\n\n1. Ensure you have followed the instructions in [Set up CTS automated testing](/docs/compatibility/cts/setup).\n2. On your test workstation, launch the CTS console by running the `cts-tradefed` script from the folder where the CTS package has been unzipped:\n\n ./android-cts/tools/cts-tradefed\n\n The CTS console displays a cursor for you to type CTS commands\n (`cts-tradefed \u003e`).\n3. The `cts` test plan contains all of the automated CTS tests. Execute the\n following command to run the `cts` test plan:\n\n run cts\n\n The automated CTS tests execute. Note the following:\n - Android 13 and higher support multidevice testing. These tests run\n automatically only when sharding is used. For further information on sharding,\n see [Improve test execution time](#improve). If you want to run these tests\n manually, see [Run multidevice tests](#multi-device-testing).\n\n - Whenever running CTS, press **ctrl+c** to stop the existing CTS console\n and then rerun the CTS console.\n\n - You can't run multiple CTS versions on single host because each opens\n with an existing open location code (OLC) server.\n\n4. View test results. For more information, see [Interpret CTS results](/docs/compatibility/cts/interpret).\n\n5. If this is your first test run, there might be tests that fail due to issues beyond your control. For example, a network connection might be slow or a GPS signal might be weak. Rerun (retry) the tests until all test modules are completed and the test failure numbers are the same between the last two retry sessions:\n\n run retry --retry \u003cvar translate=\"no\"\u003esession_number\u003c/var\u003e`\n\n | **Note:** For implementation details for CTS retry, see [Use suite retry](/docs/core/tests/tradefed/testing/through-suite/suite-retry).\n | **Note:** For instructions on how to run a retry session on Android 10 or lower, see [Run CTS automated tests (AOSP 10 or lower)](/docs/compatibility/cts/run-older).\n6. After tests failures are consistent across retries, focus on debugging\n the remaining failed tests. For information on troubleshooting test\n results, see\n [Triage test failures](/docs/compatibility/cts/interpret#triaging-test-failures)\n and\n [Troubleshoot CTS tests](/docs/compatibility/cts/troubleshooting).\n\n| **Note:** For a list of all CTS console commands, see [CTS v2 command console](/compatibility/cts/command-console-v2).\n\nRun CTS for multiscreen devices\n-------------------------------\n\nIf your device is running Android 11 or 12, and your device has multiple\nscreens, you must run the `cts-foldable` test plan separately: \n\n run cts-foldable\n\nPassed or failed test cases for alternate screen mode are appended with the\nvalue from `display_mode`, for example, `testcase1[display_mode=0]`.\n| **Note:** For instructions on how to run the `cts-foldable` test plan for Android 10 or lower, see [Run CTS automated tests (Android 10 or lower)](/docs/compatibility/cts/run-older).\n\nRun multidevice tests (Android 15 or lower)\n-------------------------------------------\n\nExecute the following command to run the `cts-multidevice` test plan: \n\n run cts-multidevice\n\nRun individual test plans\n-------------------------\n\nInstead of running all test plans at once, you can run individual test plans.\nThis option is useful to save time and to focus on a specific set of tests.\nTo run an individual test plan:\n\n1. Identify the name of the test plan you want to run by executing the `list modules` command.\n\n | **Note:** For instructions on how to identify the module on Android 10 or lower, see [Run CTS automated tests (Android 10 or lower)](/docs/compatibility/cts/run-older).\n2. Run the test plan:\n\n run cts --plan \u003cvar translate=\"no\"\u003etest_module_or_plan_name\u003c/var\u003e\n\nImprove test execution time\n---------------------------\n\nIf you want to improve test execution time, you can shard tests across multiple\ndevices. Sharding requires the host to connect at least two devices, but six or\nmore devices are recommended for efficiency.\n\nTo shard tests on Android 11 or higher, run: \n\n run cts --shard-count \u003cvar translate=\"no\"\u003enumber_of_shards\u003c/var\u003e\n\nAdditionally, before running your tests for validation you can improve test\nexecution time by using the CTS `run cts-dev` command. This command skips\npreconditions, device-information collection, and all system status checkers.\nIt also runs the tests on only a single ABI."]]