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 thejava_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 namedHelloWorldHostTest.jar
. In addition, this setting also defines a make target name for your module, so that you can usemake [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", ],