ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ภาพรวมของสหพันธ์การค้า
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Trade Federation (Tradefed หรือ TF ย่อมาจาก Trade Federation) เป็นเฟรมเวิร์กการทดสอบแบบต่อเนื่องที่ออกแบบมาสำหรับการทดสอบในอุปกรณ์ Android เช่น Tradefed ใช้เพื่อเรียกใช้ชุดเครื่องมือทดสอบความเข้ากันได้ (CTS) และชุดเครื่องมือทดสอบของผู้ให้บริการ (VTS)
Trade Federation เป็นแอปพลิเคชัน Java ที่ทำงานบนคอมพิวเตอร์โฮสต์และสื่อสารกับอุปกรณ์ Android ตั้งแต่ 1 เครื่องขึ้นไปโดยใช้ ddmlib (ไลบรารีที่อยู่เบื้องหลัง DDMS) ผ่าน adb
เราได้แสดงฟีเจอร์หลักของ TF บางส่วนไว้ด้านล่างพร้อมกับตัวอย่าง Use Case 2 รายการ อย่างไรก็ตาม หากต้องการเริ่มต้นใช้งานทันที ให้ไปที่หน้าเริ่มต้นที่นี่
ฟีเจอร์
- การออกแบบแบบโมดูลาร์ที่ยืดหยุ่นและปรับขนาดได้
- มีการสนับสนุนการเรียกใช้การทดสอบ Android หลายประเภทในตัว
การทดสอบ
uiautomator
เนทีฟ/gtest, JUnit บนโฮสต์ ฯลฯ
- มอบความน่าเชื่อถือและกลไกการกู้คืนเพิ่มเติมจาก adb
- รองรับการกำหนดเวลาและทำการทดสอบในอุปกรณ์หลายเครื่องพร้อมกัน
ดูข้อมูลล่าสุดเกี่ยวกับวิธีเรียกใช้การทดสอบที่มีอยู่ เช่น เครื่องมือวัดประสิทธิภาพ ได้ที่การทดสอบผ่าน TF
กรณีการใช้งาน
ความเป็นโมดูลของ Trade Federation ทำให้คุณติดตั้งใช้งานในสภาพแวดล้อมที่มีโครงสร้างพื้นฐานการสร้าง การทดสอบ และการรายงานที่มีอยู่ได้อย่างง่ายดาย ด้านล่างนี้คือตัวอย่าง Use Case 2-3 รายการที่ TradeFed ช่วยให้สามารถทดสอบได้อย่างมีประสิทธิภาพและปรับขนาดได้
ก่อนอื่น คุณควรพิจารณาภาพรวมของ Use Case ที่เป็นไปได้ในแง่ของคำถามที่ว่า "ส่วนใดแก้ไขได้และส่วนใดแก้ไขไม่ได้" ตัวอย่างเช่น OEM ของอุปกรณ์สามารถแก้ไขเฟรมเวิร์ก ระบบ และฮาร์ดแวร์ได้ แต่มีอิทธิพลต่อแอปพลิเคชันที่มีอยู่น้อยหรือไม่มีเลย
ส่วนนักพัฒนาแอปพลิเคชันจะแก้ไขแอปได้ แต่มีการควบคุมด้านต่างๆ ส่วนใหญ่ของระบบหรือเฟรมเวิร์กเพียงเล็กน้อย
ด้วยเหตุนี้ เอนทิตีในแต่ละ Use Case จึงมีเป้าหมายการทดสอบที่แตกต่างกัน และจะมีตัวเลือกที่แตกต่างกันในกรณีที่ชุดการทดสอบไม่ผ่าน แม้จะมีความแตกต่างกันเหล่านี้ แต่ Trade Federation ก็สามารถช่วยให้กระบวนการทดสอบแต่ละรายการมีประสิทธิภาพ ยืดหยุ่น และปรับขนาดได้
OEM ของอุปกรณ์
OEM ของอุปกรณ์จะสร้างฮาร์ดแวร์ และมักจะปรับแต่งระบบและเฟรมเวิร์กของ Android ให้ทำงานได้ดีบนฮาร์ดแวร์นั้น OEM อาจพยายามบรรลุเป้าหมายเหล่านั้นไปพร้อมกับคงความเสถียรและประสิทธิภาพไว้ในระดับฮาร์ดแวร์และระบบ รวมถึงตรวจสอบว่าการเปลี่ยนแปลงเฟรมเวิร์กจะไม่ทำให้แอปพลิเคชันที่มีอยู่ใช้งานร่วมกันไม่ได้
OEM อาจใช้โมดูลการแฟลชอุปกรณ์ที่จะทำงานในระยะการตั้งค่าเป้าหมายของวงจร โมดูลดังกล่าวจะควบคุมอุปกรณ์ได้อย่างเต็มที่ในระหว่างที่ทำงาน ซึ่งอาจทำให้อุปกรณ์เข้าสู่ Bootloader, แฟลช แล้วบังคับให้อุปกรณ์รีบูตกลับไปยังโหมดพื้นที่ผู้ใช้ เมื่อรวมกับข้อบังคับเพื่อเชื่อมโยงกับระบบบิลด์แบบต่อเนื่องแล้ว การดำเนินการนี้จะช่วยให้ OEM ทำการทดสอบในอุปกรณ์ได้ขณะทำการเปลี่ยนแปลงเฟิร์มแวร์ระดับระบบและเฟรมเวิร์กระดับ Java
เมื่ออุปกรณ์บูตขึ้นอย่างสมบูรณ์แล้ว OEM จะสามารถใช้ประโยชน์จากการทดสอบที่ใช้ JUnit ที่มีอยู่ หรือเขียนการทดสอบใหม่เพื่อยืนยันฟังก์ชันการทำงานที่ต้องการ สุดท้าย ผู้ใช้อาจเขียนข้อบังคับการรายงานผลลัพธ์อย่างน้อย 1 ข้อเพื่อเชื่อมโยงกับที่เก็บข้อมูลผลลัพธ์การทดสอบที่มีอยู่ หรือเพื่อรายงานผลลัพธ์โดยตรง (เช่น ทางอีเมล)
นักพัฒนาแอป
นักพัฒนาแอปพลิเคชันจะสร้างแอปที่ทำงานได้ดีในแพลตฟอร์มและอุปกรณ์ที่หลากหลาย หากเกิดปัญหาขึ้นในแพลตฟอร์มและ/หรืออุปกรณ์เวอร์ชันหนึ่งๆ วิธีแก้ไขเพียงอย่างเดียวคือเพิ่มวิธีแก้ปัญหาเบื้องต้นและดำเนินการต่อ สําหรับนักพัฒนาแอปรายใหญ่ กระบวนการทดสอบอาจรวมอยู่ในลําดับการสร้างแบบต่อเนื่อง สำหรับนักพัฒนาแอปรายเล็ก เราอาจเริ่มการตรวจสอบเป็นระยะๆ หรือตรวจสอบด้วยตนเอง
นักพัฒนาแอปส่วนใหญ่จะใช้โมดูลการติดตั้งการทดสอบ APK ที่มีอยู่ใน TF อยู่แล้ว
โดยจะมีเวอร์ชันที่ติดตั้งจากไฟล์ระบบในเครื่อง และเวอร์ชันที่ติดตั้ง apk ที่ดาวน์โหลดจากบริการสร้าง โปรดทราบว่าเวอร์ชันหลังจะยังคงทํางานได้อย่างถูกต้องกับอินสแตนซ์ TF จำนวนมากที่ทำงานอยู่บนเครื่องโฮสต์เครื่องเดียวกัน
เนื่องจาก TF มีความเชี่ยวชาญในการจัดการกับอุปกรณ์หลายเครื่อง การแยกประเภทผลการทดสอบแต่ละรายการตามประเภทของอุปกรณ์ที่ใช้ทดสอบนั้นจึงเป็นเรื่องง่าย ดังนั้น TF จึงอาจสร้างเมทริกซ์ความเข้ากันได้ 2 มิติ (หรือหลายมิติ) สําหรับบิลด์ทั้งหมดของแอปพลิเคชัน
บริการทดสอบ
ตัวอย่างเช่น บริการทดสอบอาจอนุญาตให้นักพัฒนาแอปส่งแอปและทำการทดสอบในอุปกรณ์ที่ติดตั้งเครื่องมือวัดพลังงานเพื่อระบุการใช้พลังงานของแอป ซึ่งแตกต่างจาก Use Case 2 รายการก่อนหน้าตรงที่เครื่องมือสร้างบริการไม่ได้ควบคุมอุปกรณ์หรือแอปพลิเคชันที่ใช้งานอยู่
เนื่องจาก Trade Federation สามารถเรียกใช้คลาส Java ใดก็ได้ที่ใช้อินเทอร์เฟซ IRemoteTest
แบบง่าย คุณจึงเขียนไดรเวอร์ที่ประสานงานกับฮาร์ดแวร์ภายนอกบางอย่างกับกรณีทดสอบที่ทำงานบนอุปกรณ์ได้ง่ายๆ ตัวไดรเวอร์เองสามารถสร้างเธรด ส่งคําขอไปยังเซิร์ฟเวอร์อื่นๆ หรือทําสิ่งอื่นๆ ที่จําเป็นได้ นอกจากนี้ ความเรียบง่ายและอเนกประสงค์ของอินเทอร์เฟซการรายงานผลลัพธ์ ITestInvocationListener
ยังช่วยให้คุณแสดงผลลัพธ์การทดสอบแบบกำหนดเอง (รวมถึงเมตริกกำลังเชิงตัวเลข) ในไปป์ไลน์การรายงานผลลัพธ์มาตรฐานได้ง่ายๆ
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# Trade Federation overview\n\nTrade Federation (Tradefed or TF for short) is a continuous test framework designed for running\ntests on Android devices. For example, Tradefed is used to run the\n[Compatibility Test Suite (CTS)](/docs/compatibility/cts) and\n[Vendor Test Suite (VTS)](/docs/core/tests/vts).\n\nTrade Federation is a Java application which runs on a host computer, and communicates to one or\nmore Android devices using ddmlib (the library behind DDMS) over adb.\n\nWe've listed some of TF's main features below, along with a couple sample usecases. That said,\nif you want to jump right in and get started, you can head straight for the\n[Start Here](/docs/core/tests/tradefed/fundamentals) page.\n\nFeatures\n--------\n\n- modular, flexible, scalable design\n- has built in support for running many different types of Android tests: [instrumentation](https://developer.android.com/studio/test#create_instrumented_test_for_a_build_variant), [uiautomator](https://developer.android.com/training/testing/ui-testing), native/gtest, host-based JUnit, etc\n- provides reliability and recovery mechanisms on top of adb\n- supports scheduling and running tests on multiple devices in parallel\n\nSee [Testing Through TF](/docs/core/tests/tradefed/testing/through-tf)\nfor the most up-to-date information about how to run your existing tests, such as\n[Instrumentation](/docs/core/tests/tradefed/testing/through-tf/instrumentation).\n\nUse cases\n---------\n\nTrade Federation's modularity makes it straightforward to slot into environments with existing\nbuild, test, and reporting infrastructures. We list below a few demonstrative\nusecases where tradefed could enable efficient, scalable test practices.\n\nFirst, it is useful to consider the landscape of potential usecases in terms of the question\n\"which parts are modifiable, and what parts are static?\" For instance, a Device OEM can modify the\nframework, the system, and the hardware, but has little or no influence over existing applications.\nAn application developer, on the other hand, can modify the app, but has little control over most\naspects of the system or the framework.\n\nAs a result, an entity in each usecase will have different testing goals, and will have different\noptions in the case of a set of test failures. Despite these differences, Trade Federation can\nhelp make each of their test processes efficient, flexible, and scalable.\n\n### Device OEM\n\nA Device OEM builds hardware, and will often tweak the Android system and frameworks to run well\non that hardware. The OEM might strive to accomplish those goals while retaining stability\nand performance at the hardware and system levels, and making sure the framework changes don't break\ncompatibility with existing applications.\n\nThe OEM could implement a device flashing module that will execute during the Target Setup stage\nof the [lifecycle](/docs/core/tests/tradefed/fundamentals/lifecycle). That\nmodule would have complete control over the device during its execution period, which would allow\nit to potentially force the device into the bootloader, flash, and then force the device to reboot\nback into userspace mode. Combined with a module to tie into a continuous build system, this would\nallow the OEM to run tests on their device as they make changes to the system-level firmware and\nJava-level frameworks.\n\nOnce the device is fully booted, the OEM would be able to leverage existing JUnit-based tests,\nor write new ones, to verify the functionality of interest. Finally, they could write one or more\nresult reporting modules to tie into existing test-result repositories, or to report results\ndirectly (for instance,\n[by email](/reference/com/android/tradefed/result/EmailResultReporter)).\n\n### App developer\n\nAn Application Developer builds an app which needs to run well across a variety of platform\nversions and a variety of devices. If an issue comes up on a particular platform version and/or\ndevice, the only remedy is to add a workaround and move on. For larger developers, the test\nprocess might be incorporated into a continuous build sequence. For smaller developers, it\nmight be kicked off periodically or by hand.\n\nMost app developers would use the apk test installation modules that already exist in TF.\nThere's a version that [installs from the local filesystem](/reference/com/android/tradefed/targetprep/InstallApkSetup), as well as a version that can\n[install\napks downloaded from a build service](/reference/com/android/tradefed/targetprep/InstallBuildEnvApkSetup). It is important to note that the latter version would\ncontinue to work properly with arbitrarily many TF instances running on the same host machine.\n\nBecause of TF's proficiency at dealing with multiple devices, it would be straightforward to\nclassify each test result by the type of device that was used for that test. Thus, TF could\npotentially generate a 2-dimensional (or multi-dimensional) compatibility matrix for every\nbuild of the application.\n\n### Testing service\n\nA Test Service might, for instance, allow app developers to submit apps and run tests on devices\ninstrumented with power-measurement tools to determine power usage for the app. This differs from\nthe prior two usecases in that the service builder does not control the devices or the applications\nthat are being run.\n\nBecause Trade Federation can run any Java class that implements the simple\n[`IRemoteTest`](/reference/com/android/tradefed/testtype/IRemoteTest) interface, it's\ntrivial to write drivers that can coordinate some external piece of hardware with the test case\nthat's being run on the device. The driver itself can spawn Threads, send requests to other\nservers, or do anything else that it might need. Moreover, the simplicity and versatility of the\nresult reporting interface,\n[`ITestInvocationListener`](/reference/com/android/tradefed/result/ITestInvocationListener), means that it is likewise straightforward to\nrepresent arbitrary test results (including, for instance, numerical power metrics) into the\nstandard result reporting pipeline."]]