हमारा सुझाव है कि 27 मार्च, 2025 से AOSP को बनाने और उसमें योगदान देने के लिए, aosp-main
के बजाय android-latest-release
का इस्तेमाल करें. ज़्यादा जानकारी के लिए, AOSP में हुए बदलाव लेख पढ़ें.
JAR होस्ट टेस्ट
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
आपके सॉफ़्टवेयर के पूरे कोड को कवर करने के लिए, Java archive (JAR) होस्ट टेस्ट लागू किए जाने चाहिए. लोकल यूनिट टेस्ट बनाने के लिए, निर्देशों का पालन करें.
किसी खास फ़ंक्शन की पुष्टि करने के लिए, छोटे यूनिट टेस्ट लिखें.
उदाहरण
नीचे दी गई ब्लूप्रिंट फ़ाइल में, Hello World JAR होस्ट टेस्ट का एक आसान उदाहरण दिया गया है. इसे कॉपी करके अपनी ज़रूरतों के हिसाब से बदला जा सकता है:
platform_testing/tests/example/jarhosttest/Android.bp
यह उस असल टेस्ट कोड से मेल खाता है जो यहां मिलता है:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
आपकी सुविधा के लिए, ब्लूप्रिंट फ़ाइल का स्नैपशॉट यहां दिया गया है:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
शुरुआत में मौजूद java_test_host
एलान से पता चलता है कि यह एक JAR होस्ट टेस्ट है. इसका इस्तेमाल करने का उदाहरण यहां देखें:
frameworks/base/tools/powermodel/Android.bp
सेटिंग
इन सेटिंग के बारे में जानने के लिए, नीचे देखें:
java_test_host
मॉड्यूल टाइप तय होने पर (ब्लॉक की शुरुआत में), name
सेटिंग ज़रूरी है. इस सेटिंग से आपके मॉड्यूल को एक नाम मिलता है. साथ ही, जनरेट किए गए JAR का नाम और .jar
सफ़िक्स एक ही होता है. यहां दिए गए उदाहरण में,जांच के बाद बने JAR फ़ाइल का नाम HelloWorldHostTest.jar
है. इसके अलावा, इस सेटिंग से आपके मॉड्यूल के लिए, मेक टारगेट का नाम भी तय होता है, ताकि आप अपने टेस्ट मॉड्यूल और उसकी सभी डिपेंडेंसी बनाने के लिए, make [options] <HelloWorldHostTest>
का इस्तेमाल कर सकें.
name: "HelloWorldHostTest",
test_suites
सेटिंग की मदद से, Trade Federation टेस्ट हार्नेस को टेस्ट आसानी से मिल जाता है. यहां अन्य टेस्ट सुइट जोड़े जा सकते हैं, जैसे कि CTS,
ताकि JAR होस्ट टेस्ट को शेयर किया जा सके.
test_suites: ["general-tests"],
static_libs
सेटिंग, मौजूदा मॉड्यूल के APK में नाम वाले मॉड्यूल के कॉन्टेंट को शामिल करने के लिए, बिल्ड सिस्टम को निर्देश देती है.
इसका मतलब है कि नाम वाले हर मॉड्यूल से एक .jar
फ़ाइल बननी चाहिए.
मॉड्यूल के कॉन्टेंट का इस्तेमाल, संकलन के समय क्लासपथ रेफ़रंस को हल करने के लिए किया जाता है. साथ ही, इसे APK में शामिल किया जाता है.
static_libs: [
"junit",
],
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","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 (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 ],"]]