A partire dal 27 marzo 2025, ti consigliamo di utilizzare android-latest-release
anziché aosp-main
per compilare e contribuire ad AOSP. Per ulteriori informazioni, vedi Modifiche ad AOSP.
Test degli host JAR
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
I test host dell'archivio Java (JAR) devono essere implementati per fornire una copertura completa del codice del software. Segui le istruzioni per creare test di unità locali.
Scrivi piccoli test delle unità per convalidare una funzione specifica e basta.
Esempio
Il seguente file Blueprint fornisce un semplice esempio di test dell'host JAR Hello World da copiare e adattare alle tue esigenze:
platform_testing/tests/example/jarhosttest/Android.bp
Corrisponde al codice di test effettivo disponibile all'indirizzo:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
Per comodità, è inclusa un'istantanea del file Blueprint:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
La dichiarazione java_test_host
all'inizio indica che si tratta di un test dell'host JAR. Vedi un esempio di utilizzo in:
frameworks/base/tools/powermodel/Android.bp
Impostazioni
Di seguito sono riportate le spiegazioni delle seguenti impostazioni:
L'impostazione name
è obbligatoria quando viene specificato il tipo di modulo java_test_host
(all'inizio del blocco). Questa impostazione assegna un nome al modulo e il file JAR risultante avrà lo stesso nome e un suffisso .jar
. Nell'esempio riportato di seguito,il file JAR di test risultante è denominato HelloWorldHostTest.jar
. Inoltre, questa impostazione definisce anche un nome target di build per il modulo, in modo da poter utilizzare make [options] <HelloWorldHostTest>
per compilare il modulo di test e tutte le relative dipendenze.
name: "HelloWorldHostTest",
L'impostazione test_suites
rende il test facilmente rilevabile dall'ambiente di test della Federazione pubblicitaria. Qui è possibile aggiungere altre suite di test, ad esempio CTS,
in modo da poter condividere il test dell'host JAR.
test_suites: ["general-tests"],
L'impostazione static_libs
indica al sistema di compilazione di incorporare i contenuti dei moduli denominati nell'APK risultante del modulo corrente.
Ciò significa che ogni modulo denominato deve produrre un file .jar
.
I contenuti del modulo vengono utilizzati per risolvere i riferimenti al classpath durante il compilazione e incorporati nell'APK risultante.
static_libs: [
"junit",
],
I campioni di contenuti e codice in questa pagina sono soggetti alle licenze descritte nella Licenza per i contenuti. Java e OpenJDK sono marchi o marchi registrati di Oracle e/o delle sue società consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-27 UTC."],[],[],null,["# JAR host tests\n\nJava archive (JAR) host tests should be implemented to provide complete code\ncoverage of your software. Follow the instructions to [Build local unit\ntests](https://developer.android.com/training/testing/unit-testing/local-unit-tests).\nWrite small unit tests to validate a specific function and nothing more.\n\nExample\n-------\n\nThe following Blueprint file provides a simple Hello World JAR host test example\nto copy and adapt to your needs:\n[platform_testing/tests/example/jarhosttest/Android.bp](https://android.googlesource.com/platform/platform_testing/+/android16-release/tests/example/jarhosttest/Android.bp)\n\nThis corresponds to the actual test code found at:\n[platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java](https://android.googlesource.com/platform/platform_testing/+/android16-release/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java)\n\nA snapshot of the Blueprint file is included here for convenience: \n\n java_test_host {\n name: \"HelloWorldHostTest\",\n\n test_suites: [\"general-tests\"],\n\n srcs: [\"test/**/*.java\"],\n\n static_libs: [\n \"junit\",\n \"mockito\",\n ],\n }\n\nThe `java_test_host` declaration at the beginning indicates that this is a JAR\nhost test. See an example of its use in:\n[frameworks/base/tools/powermodel/Android.bp](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/tools/powermodel/Android.bp)\n\nSettings\n--------\n\nSee below for explanations of the following settings:\n\n- The `name` setting is required when the `java_test_host` module type is\n specified (at the start of the block). This setting gives a name to your\n module, and the resulting JAR has the same name and a `.jar` suffix. In the\n example below,the resulting test JAR is named `HelloWorldHostTest.jar`. In\n addition, this setting also defines a make target name for your module, so\n that you can use `make [options] \u003cHelloWorldHostTest\u003e` to build your test\n module and all its dependencies.\n\n name: \"HelloWorldHostTest\",\n\n- The `test_suites` setting makes the test easily discoverable by the Trade\n Federation test harness. Other test suites can be added here, such as CTS,\n so that the JAR host test test can be shared.\n\n test_suites: [\"general-tests\"],\n\n- The `static_libs` setting instructs the build system to incorporate the\n contents of the named modules into the resulting APK of the current module.\n This means that each named module is expected to produce a `.jar` file.\n The module's content is used for resolving classpath references during\n compile time and incorporated into the resulting APK.\n\n static_libs: [\n \"junit\",\n ],"]]