Add java_test and java_test_host
java_test is equivalent to a java_library with a default junit
dependency and marked as a test in Make for installation and
automatic AndroidTest.xml generation.
Bug: 70770641
Test: m checkbuild
Change-Id: I9ca97521e952d121db46abff6f24f274dd7a3ad7
diff --git a/java/androidmk.go b/java/androidmk.go
index 1e15779..fff034c 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -97,6 +97,19 @@
}
}
+func (j *Test) AndroidMk() android.AndroidMkData {
+ data := j.Library.AndroidMk()
+ data.Extra = append(data.Extra, func(w io.Writer, outputFile android.Path) {
+ fmt.Fprintln(w, "LOCAL_MODULE_TAGS := tests")
+ if len(j.testProperties.Test_suites) > 0 {
+ fmt.Fprintln(w, "LOCAL_COMPATIBILITY_SUITE :=",
+ strings.Join(j.testProperties.Test_suites, " "))
+ }
+ })
+
+ return data
+}
+
func (prebuilt *Import) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{
Class: "JAVA_LIBRARIES",
diff --git a/java/java.go b/java/java.go
index 8665681..fd0719c 100644
--- a/java/java.go
+++ b/java/java.go
@@ -39,6 +39,8 @@
android.RegisterModuleType("java_library_host", LibraryHostFactory)
android.RegisterModuleType("java_binary", BinaryFactory)
android.RegisterModuleType("java_binary_host", BinaryHostFactory)
+ android.RegisterModuleType("java_test", TestFactory)
+ android.RegisterModuleType("java_test_host", TestHostFactory)
android.RegisterModuleType("java_import", ImportFactory)
android.RegisterModuleType("java_import_host", ImportFactoryHost)
@@ -1209,6 +1211,59 @@
}
//
+// Java Junit Tests
+//
+
+type testProperties struct {
+ // If true, add a static dependency on the platform junit library. Defaults to true.
+ Junit *bool
+
+ // list of compatibility suites (for example "cts", "vts") that the module should be
+ // installed into.
+ Test_suites []string `android:"arch_variant"`
+}
+
+type Test struct {
+ Library
+
+ testProperties testProperties
+}
+
+func (j *Test) DepsMutator(ctx android.BottomUpMutatorContext) {
+ j.deps(ctx)
+ if j.testProperties.Junit == nil || *j.testProperties.Junit == true {
+ ctx.AddDependency(ctx.Module(), staticLibTag, "junit")
+ }
+}
+
+func TestFactory() android.Module {
+ module := &Test{}
+
+ module.AddProperties(
+ &module.Module.properties,
+ &module.Module.deviceProperties,
+ &module.Module.protoProperties,
+ &module.testProperties)
+
+ InitJavaModule(module, android.HostAndDeviceSupported)
+ android.InitDefaultableModule(module)
+ return module
+}
+
+func TestHostFactory() android.Module {
+ module := &Test{}
+
+ module.AddProperties(
+ &module.Module.properties,
+ &module.Module.protoProperties,
+ &module.testProperties)
+
+ InitJavaModule(module, android.HostSupported)
+ android.InitDefaultableModule(module)
+ return module
+}
+
+//
// Java Binaries (.jar file plus wrapper script)
//