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.
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.
HostUtils
public
final
class
HostUtils
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.lite.HostUtils
|
Triển khai một số phương thức tiện ích hữu ích để chạy kiểm thử máy chủ.
Phương thức này triển khai một số phương thức để tìm kiểm thử trên máy chủ và giả lập quá trình thực thi kiểm thử JUnit để chúng ta có thể "chạy thử" các kiểm thử đó.
Tóm tắt
Phương thức công khai |
static
|
getJUnitClasses( classNames, jarAbsPaths, ClassLoader pcl)
|
static
|
getJUnitClasses( classNames, jarAbsPaths, excludePaths, ClassLoader pcl)
Lấy các trường hợp kiểm thử JUnit4 từ tên lớp và đường dẫn tệp jar được cung cấp.
|
static
boolean
|
hasJUnitAnnotation(Class<?> classObj)
Kiểm tra xem một lớp có giống với kiểm thử JUnit hay không.
|
static
boolean
|
testLoadClass(String className, URLClassLoader cl, String jarName)
Kiểm tra xem lớp có phải là lớp kiểm thử phù hợp hay không.
|
Phương thức công khai
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
ClassLoader pcl)
Tham số |
classNames |
|
jarAbsPaths |
|
pcl |
ClassLoader |
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
excludePaths,
ClassLoader pcl)
Lấy các trường hợp kiểm thử JUnit4 từ tên lớp và đường dẫn tệp jar được cung cấp.
Tham số |
classNames |
: Các lớp tồn tại trong đường dẫn lớp hiện tại để kiểm tra các kiểm thử JUnit |
jarAbsPaths |
: Tệp jar để tìm kiếm các lớp có chú thích kiểm thử. |
excludePaths |
|
pcl |
ClassLoader |
Giá trị trả về |
|
danh sách các đối tượng lớp là lớp kiểm thử để thực thi. |
Gửi |
|
IllegalArgumentException |
hasJUnitAnnotation
public static boolean hasJUnitAnnotation (Class<?> classObj)
Kiểm tra xem một lớp có giống với kiểm thử JUnit hay không.
Tham số |
classObj |
Class : Lớp để kiểm tra chú thích |
Giá trị trả về |
boolean |
liệu đối tượng lớp có chú thích kiểm thử JUnit4 hay không |
testLoadClass
public static boolean testLoadClass (String className,
URLClassLoader cl,
String jarName)
Kiểm tra xem lớp có phải là lớp kiểm thử phù hợp hay không.
Trong trường hợp này, phù hợp có nghĩa là đây là một lớp kiểm thử JUnit hợp lệ sử dụng một trong các trình chạy tiêu chuẩn hoặc một lớp con của lớp đó. Rõ ràng là lớp này cũng sẽ tải.
Giá trị trả về |
boolean |
true nếu chúng ta nên coi lớp này là lớp kiểm thử, false nếu không |
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,["# HostUtils\n=========\n\n\n`\npublic\n\nfinal\n\nclass\nHostUtils\n`\n\n\n`\n\nextends Object\n\n\n`\n\n`\n\n\n`\n\n|---|-------------------------------------|\n| java.lang.Object ||\n| ↳ | com.android.tradefed.lite.HostUtils |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nImplements some useful utility methods for running host tests.\n\nThis implements a few methods for finding tests on the host and faking execution of JUnit\ntests so we can \"dry run\" them.\n\nSummary\n-------\n\n| ### Public methods ||\n|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` static ` | ` `[getJUnitClasses](../../../../../../reference/tradefed/com/android/tradefed/lite/HostUtils.html#getJUnitClasses(\u003cany\u003e,%20\u003cany\u003e,%20java.lang.ClassLoader))`(` classNames, jarAbsPaths, ClassLoader pcl) |\n| ` static ` | ` `[getJUnitClasses](../../../../../../reference/tradefed/com/android/tradefed/lite/HostUtils.html#getJUnitClasses(\u003cany\u003e,%20\u003cany\u003e,%20\u003cany\u003e,%20java.lang.ClassLoader))`(` classNames, jarAbsPaths, excludePaths, ClassLoader pcl) Gets JUnit4 test cases from provided classnames and jar paths. |\n| ` static boolean` | ` `[hasJUnitAnnotation](../../../../../../reference/tradefed/com/android/tradefed/lite/HostUtils.html#hasJUnitAnnotation(java.lang.Class\u003c?\u003e))`(Class\u003c?\u003e classObj) ` Checks whether a class looks like a JUnit test or not. |\n| ` static boolean` | ` `[testLoadClass](../../../../../../reference/tradefed/com/android/tradefed/lite/HostUtils.html#testLoadClass(java.lang.String,%20URLClassLoader,%20java.lang.String))`(String className, URLClassLoader cl, String jarName) ` Tests whether the class is a suitable test class or not. |\n\nPublic methods\n--------------\n\n### getJUnitClasses\n\n```\npublic static getJUnitClasses ( classNames, \n jarAbsPaths, \n ClassLoader pcl)\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Parameters ||\n|---------------|----------------------|\n| `classNames` | \u003cbr /\u003e |\n| `jarAbsPaths` | \u003cbr /\u003e |\n| `pcl` | `ClassLoader` \u003cbr /\u003e |\n\n| Returns ||\n|---|--------|\n| | \u003cbr /\u003e |\n\n### getJUnitClasses\n\n```\npublic static getJUnitClasses ( classNames, \n jarAbsPaths, \n excludePaths, \n ClassLoader pcl)\n```\n\nGets JUnit4 test cases from provided classnames and jar paths.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------------|--------------------------------------------------------------------------------|\n| `classNames` | : Classes that exist in the current class path to check for JUnit tests \u003cbr /\u003e |\n| `jarAbsPaths` | : Jars to search for classes with the test annotations. \u003cbr /\u003e |\n| `excludePaths` | \u003cbr /\u003e |\n| `pcl` | `ClassLoader` \u003cbr /\u003e |\n\n| Returns ||\n|---|------------------------------------------------------------------|\n| | a list of class objects that are test classes to execute. \u003cbr /\u003e |\n\n| Throws ||\n|---|--------------------------|\n| | IllegalArgumentException |\n\n### hasJUnitAnnotation\n\n```\npublic static boolean hasJUnitAnnotation (Class\u003c?\u003e classObj)\n```\n\nChecks whether a class looks like a JUnit test or not.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------------------------------------------|\n| `classObj` | `Class`: Class to examine for the annotation \u003cbr /\u003e |\n\n| Returns ||\n|-----------|----------------------------------------------------------------|\n| `boolean` | whether the class object has the JUnit4 test annotation \u003cbr /\u003e |\n\n### testLoadClass\n\n```\npublic static boolean testLoadClass (String className, \n URLClassLoader cl, \n String jarName)\n```\n\nTests whether the class is a suitable test class or not.\n\nIn this case, suitable means it is a valid JUnit test class using one of the standard\nrunners or a subclass thereof. The class should also load, obviously.\n\n\u003cbr /\u003e\n\n| Returns ||\n|-----------|----------------------------------------------------------------------------|\n| `boolean` | true if we should consider this class a test class, false otherwise \u003cbr /\u003e |"]]