ทดสอบโค้ดแพลตฟอร์มด้วย atest
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Android Studio for Platform (ASfP) ผสานรวมกับเครื่องมือatest
บรรทัดคำสั่ง
ช่วยให้คุณเรียกใช้การทดสอบในอุปกรณ์ที่เชื่อมต่อหรือโปรแกรมจำลองได้โดยตรงจาก
IDE
สิ่งที่ต้องมีก่อน
- เปิดโปรเจ็กต์ ASfP ด้วยซอร์สโค้ด AOSP
- สร้างและแฟลชโค้ดไปยังอุปกรณ์หรือโปรแกรมจำลองเรียบร้อยแล้ว
- เริ่มต้นสภาพแวดล้อมการสร้างโดยใช้
source build/envsetup.sh
และ
lunch
ทำการทดสอบ
คุณสามารถเรียกใช้การทดสอบโดยใช้ atest
ใน ASfP ได้หลายวิธี ดังนี้
ไอคอนการวิ่งในราง: คลิกไอคอนวิ่ง play_circle
ข้างคลาสหรือเมธอดการทดสอบในเอดิเตอร์เพื่อเรียกใช้การทดสอบนั้นๆ
เมนูคลิกขวา: คลิกขวาที่ไฟล์ทดสอบ คลาส หรือเมธอดใน
หน้าต่างโปรเจ็กต์หรือเอดิเตอร์ แล้วเลือกเรียกใช้ "atest"
การใช้เทอร์มินัล: เปิดเทอร์มินัลแบบผสานรวมใน ASfP (ดู > เครื่องมือ
Windows > เทอร์มินัล) และเรียกใช้คำสั่ง atest
โดยตรง เช่น bash
atest MyTestModule
atest MyTestClass#myTestMethod
ดูผลการทดสอบ
ผลการทดสอบจะแสดงในหน้าต่างเครื่องมือเรียกใช้ภายใน ASfP หน้าต่างนี้
จะแสดงความคืบหน้าในการทดสอบ สถานะผ่านหรือไม่ผ่าน รวมถึงบันทึกและเอาต์พุตของ
การทดสอบแต่ละรายการ
การกำหนดค่าการทดสอบ
เมื่อคุณเรียกใช้การทดสอบจากแถบข้างหรือเมนูคลิกขวา ASfP จะสร้างการกำหนดค่าการเรียกใช้หรือการแก้ไขข้อบกพร่องชั่วคราวโดยอัตโนมัติ
คุณสามารถแก้ไขและบันทึกการกำหนดค่าเหล่านี้เพื่อเรียกใช้การทดสอบอีกครั้งอย่างรวดเร็วด้วยตัวเลือกหรือ Flag ที่เฉพาะเจาะจงได้โดยทำดังนี้
- ไปที่เรียกใช้ > แก้ไขการกำหนดค่า
- ค้นหา
atest
การกำหนดค่าที่ต้องการแก้ไขหรือสร้างการกำหนดค่าใหม่โดย
คลิกปุ่ม + แล้วเลือกล่าสุด
- ระบุโมดูลการทดสอบ คลาส เมธอด และเพิ่ม
atest
ตัวเลือกบรรทัดคำสั่งที่จำเป็น
เคล็ดลับในการทดสอบ
- การทดสอบที่กำหนดเป้าหมาย: เรียกใช้เฉพาะการทดสอบที่ต้องการเพื่อประหยัดเวลา ใช้
รูปแบบ
Module:Class#Method
หรือฟิลเตอร์atest
อื่นๆ
- ใช้สแนปชอตของโปรแกรมจำลอง: หากต้องการทดสอบในโปรแกรมจำลองได้เร็วขึ้น ให้ลอง
ใช้สแนปชอตเพื่อกลับไปใช้สถานะที่ทราบว่าดีได้อย่างรวดเร็ว
- ตรวจสอบบันทึก: ใช้บันทึกในหน้าต่างเครื่องมือเรียกใช้เพื่อวินิจฉัยการทดสอบที่ล้มเหลว
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-05 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-09-05 UTC"],[],[],null,["Android Studio for Platform (ASfP) integrates with the `atest` command-line\ntool, letting you run tests on your connected device or emulator directly from\nthe IDE.\n\nPrerequisites\n\n- Open an ASfP project with your AOSP source code.\n- Successfully build and flash your code to a device or emulator.\n- Initialize your build environment using `source build/envsetup.sh` and `lunch`.\n\nRun tests\n\nYou can run tests using `atest` in ASfP in several ways:\n\n- **Gutter run icons:** Click the **Run** icon play_circle\n\n next to a test class or method in the editor to run that specific test.\n- **Right-click menu:** Right-click on a test file, class, or method in the\n Project window or editor and select **Run 'atest'**.\n\n- **Using the terminal:** Open the integrated terminal in ASfP (**View \\\u003e Tool\n Windows \\\u003e Terminal** ) and run `atest` commands directly. For example: `bash\n atest MyTestModule\n atest MyTestClass#myTestMethod`\n\nView test results\n\nTest results are displayed in the **Run** tool window within ASfP. This window\nshows the test progress, pass or fail status, and provides logs and output for\neach test.\n\nTest configurations\n\nWhen you run a test from the gutter or right-click menu, ASfP automatically\ncreates a temporary run or debug configuration. You can modify and save these\nconfigurations to quickly re-run tests with specific options or flags:\n\n1. Go to **Run \\\u003e Edit Configurations**.\n2. Find the `atest` configuration you want to modify or create a new one by clicking the **+** button and selecting **atest**.\n3. Specify the test module, class, method, and add any necessary `atest` command-line options.\n\nTips for testing\n\n- **Targeted testing:** Run only the specific tests you need to save time. Use the format `Module:Class#Method` or other `atest` filters.\n- **Use emulator snapshots:** For faster test runs on emulators, consider using snapshots to quickly revert to a known good state.\n- **Check logs:** Use the logs in the **Run** tool window to diagnose any test failures."]]