Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
HostUtils
public
final
class
HostUtils
extends Object
java.lang.Object
|
↳ |
com.android.tradefed.lite.HostUtils
|
Implementuje przydatne metody narzędzi do uruchamiania testów hosta.
W tym celu stosuje się kilka metod wyszukiwania testów na hoście i udawania wykonywania testów JUnit, aby można było je „testować na sucho”.
Podsumowanie
Metody publiczne |
static
|
getJUnitClasses( classNames, jarAbsPaths, ClassLoader pcl)
|
static
|
getJUnitClasses( classNames, jarAbsPaths, excludePaths, ClassLoader pcl)
Pobiera przypadki testowe JUnit4 z podanych nazw klas i ścieżek do plików JAR.
|
static
boolean
|
hasJUnitAnnotation(Class<?> classObj)
Sprawdza, czy klasa wygląda jak test JUnit.
|
static
boolean
|
testLoadClass(String className, URLClassLoader cl, String jarName)
Sprawdza, czy klasa jest odpowiednią klasą testową.
|
Metody publiczne
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
ClassLoader pcl)
Parametry |
classNames |
|
jarAbsPaths |
|
pcl |
ClassLoader |
getJUnitClasses
public static getJUnitClasses ( classNames,
jarAbsPaths,
excludePaths,
ClassLoader pcl)
Pobiera przypadki testowe JUnit4 z podanych nazw klas i ścieżek do plików JAR.
Parametry |
classNames |
: klasy znajdujące się na bieżącej ścieżce klas, w których mają być sprawdzane testy JUnit |
jarAbsPaths |
: Jars do wyszukiwania klas z adnotacjami testowymi. |
excludePaths |
|
pcl |
ClassLoader |
Zwroty |
|
lista obiektów klas, które są klasami testowymi do wykonania; |
Rzuty |
|
IllegalArgumentException |
hasJUnitAnnotation
public static boolean hasJUnitAnnotation (Class<?> classObj)
Sprawdza, czy klasa wygląda jak test JUnit.
Parametry |
classObj |
Class : klasa do sprawdzenia pod kątem adnotacji |
Zwroty |
boolean |
czy obiekt klasy ma adnotację testu JUnit4 |
testLoadClass
public static boolean testLoadClass (String className,
URLClassLoader cl,
String jarName)
Sprawdza, czy klasa jest odpowiednią klasą testową.
W tym przypadku „odpowiednia” oznacza, że jest to prawidłowa klasa testu JUnit, która korzysta z jednego ze standardowych runnerów lub jego podklasy. Oczywiście klasa powinna się też wczytać.
Zwroty |
boolean |
wartość true, jeśli te zajęcia powinny być traktowane jako zajęcia testowe, w przeciwnym razie wartość false |
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-27 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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 |"]]