Starting March 27, 2025, we recommend using android-latest-release
instead of aosp-main
to build and contribute to AOSP. For more information, see Changes to AOSP.
JAR host tests
Stay organized with collections
Save and categorize content based on your preferences.
Java archive (JAR) host tests should be implemented to provide complete code
coverage of your software. Follow the instructions to Build local unit
tests.
Write small unit tests to validate a specific function and nothing more.
Example
The following Blueprint file provides a simple Hello World JAR host test example
to copy and adapt to your needs:
platform_testing/tests/example/jarhosttest/Android.bp
This corresponds to the actual test code found at:
platform_testing/tests/example/jarhosttest/test/android/test/example/helloworld/HelloWorldTest.java
A snapshot of the Blueprint file is included here for convenience:
java_test_host {
name: "HelloWorldHostTest",
test_suites: ["general-tests"],
srcs: ["test/**/*.java"],
static_libs: [
"junit",
"mockito",
],
}
The java_test_host
declaration at the beginning indicates that this is a JAR
host test. See an example of its use in:
frameworks/base/tools/powermodel/Android.bp
Settings
See below for explanations of the following settings:
The name
setting is required when the java_test_host
module type is
specified (at the start of the block). This setting gives a name to your
module, and the resulting JAR has the same name and a .jar
suffix. In the
example below,the resulting test JAR is named HelloWorldHostTest.jar
. In
addition, this setting also defines a make target name for your module, so
that you can use make [options] <HelloWorldHostTest>
to build your test
module and all its dependencies.
name: "HelloWorldHostTest",
The test_suites
setting makes the test easily discoverable by the Trade
Federation test harness. Other test suites can be added here, such as CTS,
so that the JAR host test test can be shared.
test_suites: ["general-tests"],
The static_libs
setting instructs the build system to incorporate the
contents of the named modules into the resulting APK of the current module.
This means that each named module is expected to produce a .jar
file.
The module's content is used for resolving classpath references during
compile time and incorporated into the resulting APK.
static_libs: [
"junit",
],
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-06-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-18 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 ],"]]