ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ผู้เตรียมข้อมูลเป้าหมาย
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ระบบจะเรียกใช้เครื่องมือเตรียมเป้าหมายก่อนการทดสอบในระดับการทดสอบที่กําหนดไว้ ซึ่งจะช่วยให้การตั้งค่าอุปกรณ์สำหรับการทดสอบทำงานได้อย่างราบรื่น
อินเทอร์เฟซพื้นฐาน
อินเทอร์เฟซพื้นฐานคือ ITargetPreparer
ซึ่งช่วยให้สามารถใช้งานเมธอด setUp
ได้ เราขอแนะนําให้ใช้คลาสนามธรรมพื้นฐานของเรา BaseTargetPreparer
ซึ่งมีฟีเจอร์ปิดใช้ในตัวเพื่อให้ปิดใช้เครื่องมือเตรียมข้อมูลได้ง่ายๆ
อินเทอร์เฟซที่สะอาดตา
ส่วนขยายตามปกติของ setUp
คือ tearDown
ซึ่งให้บริการโดยอินเทอร์เฟซอื่น ITargetCleaner
ซึ่งจะมีอินเทอร์เฟซ tearDown
ที่ช่วยให้ล้างข้อมูลทั้งหมดที่ทำใน setUp
หลังจากการทดสอบได้
ชั้นเรียน BaseTargetPreparer
ยังขยายเวลา ITargetCleaner
ด้วย
คำแนะนำ
เราขอแนะนำให้ผู้เตรียมแต่ละรายมีฟังก์ชันหลักเพียงฟังก์ชันเดียว เช่น การติดตั้ง APK หรือเรียกใช้คำสั่ง ซึ่งช่วยให้ใช้ผู้จัดเตรียมซ้ำได้ง่ายขึ้น
นอกจากนี้ ให้ตรวจสอบรายการผู้เตรียมความพร้อมที่มีอยู่ก่อนที่จะเพิ่มผู้เตรียมความพร้อมรายใหม่เพื่อหลีกเลี่ยงการทำงานซ้ำ ผู้เตรียมแบบฟอร์มมีให้บริการใน tools/tradefederation/core/src/com/android/tradefed/targetprep/
การกําหนดค่า XML
แท็กออบเจ็กต์คือ target_preparer
เช่น
<target_preparer class="com.android.tradefed.targetprep.InstallApkSetup">
<option name="install-arg" value="-d"/>
</target_preparer>
โปรดดูบริบทเพิ่มเติมจากหัวข้อตั้งค่าชุด
การตั้งค่าระดับบนสุด
หากระบุไว้ในการตั้งค่าระดับบนสุด เครื่องมือเตรียมจะทำงานเพียงครั้งเดียวสำหรับอุปกรณ์แต่ละเครื่อง ตัวอย่างเช่น cts-common.xml
ซึ่งเป็นการตั้งค่าระดับบนสุดสำหรับการทดสอบชุดเครื่องมือทดสอบความเข้ากันได้ (CTS) ของ Android
การตั้งค่าระดับโมดูล
หากระบุที่ระดับโมดูล เครื่องมือเตรียมจะทำงานก่อนโมดูลนั้นเสมอ ตัวอย่างเช่น backup/AndroidTest.xml
ซึ่งกําหนดวิธีให้ Tradefed เรียกใช้โมดูล backup
CTS
โปรดทราบว่าแม้ว่าเครื่องมือเตรียมจะทำงานก่อนโมดูล แต่เครื่องมือจะทำงานหลังเครื่องมือตรวจสอบสถานะระบบ
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Target preparers are invoked before the tests in the\n[test level](/docs/core/tests/tradefed/testing/through-suite/setup#definitions)\nin which they are defined. This allows the setup of any device for tests to run\nsmoothly.\n\nBase interface\n--------------\n\nThe base interface is\n[`ITargetPreparer`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/ITargetPreparer.java),\nwhich allows implementation of a `setUp` method to be executed. We\nrecommend implementing our basic abstract class\n[`BaseTargetPreparer`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/BaseTargetPreparer.java),\nwhich provides a built-in disablement feature to easily disable a preparer.\n\nCleaner interface\n-----------------\n\nThe natural extension of `setUp` is `tearDown` and is provided by a different\ninterface,\n[`ITargetCleaner`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/ITargetCleaner.java). That provides the `tearDown` interface\nthat allows cleaning up anything that was done in `setUp` after the test\nexecution.\n\nThe `BaseTargetPreparer` class also extends `ITargetCleaner`.\n\nRecommendations\n---------------\n\nWe recommend each preparer be limited to a single main function, for example\ninstalling an APK or running a command. This allows for easier reuse of\npreparers.\n\nAlso check the list of available preparers before adding a new one to\navoid duplicating work. Preparers are available in [`tools/tradefederation/core/src/com/android/tradefed/targetprep/`](https://android.googlesource.com/platform/tools/tradefederation/+/refs/heads/android16-release/src/com/android/tradefed/targetprep/).\n\nXML configuration\n-----------------\n\nThe object tag is `target_preparer`, for example: \n\n \u003ctarget_preparer class=\"com.android.tradefed.targetprep.InstallApkSetup\"\u003e\n \u003coption name=\"install-arg\" value=\"-d\"/\u003e\n \u003c/target_preparer\u003e\n\nAlso refer to\n[Set up suites](/docs/core/tests/tradefed/testing/through-suite/setup)\nfor context.\n\n### Top-level setup\n\nIf specified in a top-level setup, the preparer runs only once for each\ndevice. An example is\n[`cts-common.xml`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tools/cts-tradefed/res/config/cts-common.xml),\nwhich is a top-level setup for Android Compatibility Test Suite (CTS) tests.\n\n### Module-level setup\n\nIf specified at the module level, the preparer always runs before that\nmodule. An example is\n[`backup/AndroidTest.xml`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/backup/AndroidTest.xml),\nwhich defines how Tradefed runs the `backup` CTS module.\n\nNote that while the preparer runs before the module, it runs *after* any\n[system status checkers](/docs/core/tests/tradefed/testing/through-suite/system-status-checker)."]]