27 Mart 2025'ten itibaren AOSP'yi derlemek ve AOSP'ye katkıda bulunmak için aosp-main
yerine android-latest-release
kullanmanızı öneririz. Daha fazla bilgi için AOSP'de yapılan değişiklikler başlıklı makaleyi inceleyin.
JAR ana makine testleri
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Yazılımınızın kod kapsamını eksiksiz hale getirmek için Java arşivi (JAR) ana makine testleri uygulanmalıdır. Yerel birim testleri oluşturma talimatlarını uygulayın.
Belirli bir işlevi doğrulamak için küçük birim testleri yazın.
Örnek
Aşağıdaki Blueprint dosyasında, kopyalayıp ihtiyaçlarınıza göre uyarlayabileceğiniz basit bir Hello World JAR ana makine testi örneği verilmiştir:
platform_testing/tests/example/jarhosttest/Android.bp
Bu, şu konumda bulunan gerçek test koduna karşılık gelir:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
Kolaylık sağlamak için Blueprint dosyasının anlık görüntüsü buraya eklenmiştir:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
Başındaki java_test_host
beyanı, bunun bir JAR ana makine testi olduğunu gösterir. Bu işlevin kullanımına dair bir örnek için:
frameworks/base/tools/powermodel/Android.bp
Ayarlar
Aşağıdaki ayarların açıklamalarını aşağıda bulabilirsiniz:
java_test_host
modülü türü belirtildiğinde (bloğun başında) name
ayarı gereklidir. Bu ayar, modülünüze bir ad verir. Sonuç olarak oluşturulan JAR dosyası aynı ada ve .jar
son ekine sahiptir. Aşağıdaki örnekte,oluşturulan test JAR'ı HelloWorldHostTest.jar
olarak adlandırılmıştır. Ayrıca bu ayar, test modülünüzü ve tüm bağımlılıkları oluşturmak için make [options] <HelloWorldHostTest>
kullanabilmeniz amacıyla modülünüz için bir derleme hedefi adı da tanımlar.
name: "HelloWorldHostTest",
test_suites
ayarı, testi Trade Federation test aparatı tarafından kolayca bulunabilir hale getirir. JAR ana makine testi paylaşılabilmesi için buraya CTS gibi başka test paketleri de eklenebilir.
test_suites: ["general-tests"],
static_libs
ayarı, derleme sistemine adlandırılmış modüllerin içeriklerini mevcut modülün oluşturulan APK'sına dahil etmesini söyler.
Bu, her adlandırılmış modülün bir .jar
dosyası oluşturması gerektiği anlamına gelir.
Modülün içeriği, derleme sırasında sınıf yolu referanslarını çözmek için kullanılır ve oluşturulan APK'ya dahil edilir.
static_libs: [
"junit",
],
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-27 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 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 ],"]]