自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
HostUtils
public
final
class
HostUtils
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.lite.HostUtils
|
實作一些實用公用程式方法,用於執行主機測試。
這會實作幾種方法,用於在主機上尋找測試,並模擬執行 JUnit 測試,以便進行「模擬執行」。
摘要
公用方法 |
static
|
getJUnitClasses( classNames, jarAbsPaths, ClassLoader pcl)
|
static
|
getJUnitClasses( classNames, jarAbsPaths, excludePaths, ClassLoader pcl)
從提供的類別名稱和 JAR 路徑取得 JUnit4 測試案例。
|
static
boolean
|
hasJUnitAnnotation(Class<?> classObj)
檢查類別是否看起來像 JUnit 測試。
|
static
boolean
|
testLoadClass(String className, URLClassLoader cl, String jarName)
測試類別是否為適當的測試類別。
|
公用方法
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
ClassLoader pcl)
參數 |
classNames |
|
jarAbsPaths |
|
pcl |
ClassLoader |
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
excludePaths,
ClassLoader pcl)
從提供的類別名稱和 JAR 路徑取得 JUnit4 測試案例。
參數 |
classNames |
:目前類別路徑中存在的類別,用於檢查 JUnit 測試 |
jarAbsPaths |
:用於搜尋含有測試註解的類別的 JAR 檔案。 |
excludePaths |
|
pcl |
ClassLoader |
擲回 |
|
IllegalArgumentException |
hasJUnitAnnotation
public static boolean hasJUnitAnnotation (Class<?> classObj)
檢查類別是否看起來像 JUnit 測試。
參數 |
classObj |
Class :要檢查註解的類別 |
傳回 |
boolean |
類別物件是否具有 JUnit4 測試註解 |
testLoadClass
public static boolean testLoadClass (String className,
URLClassLoader cl,
String jarName)
測試類別是否為適當的測試類別。
在這種情況下,適當的意思是指使用其中一個標準執行程式或其子類別的有效 JUnit 測試類別。當然,類別也應載入。
傳回 |
boolean |
如果我們應將此類別視為測試類別,則傳回 true,否則傳回 false |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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 (世界標準時間)。"],[],[],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 |"]]