Mulai 27 Maret 2025, sebaiknya gunakan android-latest-release
, bukan aosp-main
, untuk mem-build dan berkontribusi pada AOSP. Untuk mengetahui informasi selengkapnya, lihat Perubahan pada AOSP.
Pengujian host JAR
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pengujian host arsip Java (JAR) harus diterapkan untuk memberikan cakupan kode
lengkap software Anda. Ikuti petunjuk untuk Mem-build pengujian unit lokal.
Tulis pengujian unit kecil untuk memvalidasi fungsi tertentu dan tidak lebih.
Contoh
File Blueprint berikut memberikan contoh pengujian host JAR Hello World sederhana
untuk disalin dan disesuaikan dengan kebutuhan Anda:
platform_testing/tests/example/jarhosttest/Android.bp
Ini sesuai dengan kode pengujian sebenarnya yang ditemukan di:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
Snapshot file Blueprint disertakan di sini untuk memudahkan:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
Pernyataan java_test_host
di awal menunjukkan bahwa ini adalah pengujian host JAR. Lihat contoh penggunaannya di:
frameworks/base/tools/powermodel/Android.bp
Setelan
Lihat di bawah untuk mengetahui penjelasan setelan berikut:
Setelan name
diperlukan saat jenis modul java_test_host
ditentukan (di awal blok). Setelan ini memberi nama pada
modul Anda, dan JAR yang dihasilkan memiliki nama yang sama dan akhiran .jar
. Dalam
contoh di bawah,JAR pengujian yang dihasilkan diberi nama HelloWorldHostTest.jar
. Selain itu, setelan ini juga menentukan nama target pembuatan untuk modul Anda, sehingga
Anda dapat menggunakan make [options] <HelloWorldHostTest>
untuk mem-build modul
pengujian dan semua dependensinya.
name: "HelloWorldHostTest",
Setelan test_suites
membuat pengujian mudah ditemukan oleh harness pengujian Trade
Federation. Test suite lain dapat ditambahkan di sini, seperti CTS,
sehingga pengujian host JAR dapat dibagikan.
test_suites: ["general-tests"],
Setelan static_libs
menginstruksikan sistem build untuk menggabungkan
konten modul yang dinamai ke dalam APK yang dihasilkan dari modul saat ini.
Artinya, setiap modul yang diberi nama diharapkan akan menghasilkan file .jar
.
Konten modul digunakan untuk me-resolve referensi classpath selama
waktu kompilasi dan digabungkan ke dalam APK yang dihasilkan.
static_libs: [
"junit",
],
Konten dan contoh kode di halaman ini tunduk kepada lisensi yang dijelaskan dalam Lisensi Konten. Java dan OpenJDK adalah merek dagang atau merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-27 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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 ],"]]