summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Dan Shi <dshi@google.com> 2017-12-22 13:32:48 -0800
committer Dan Shi <dshi@google.com> 2017-12-22 13:34:50 -0800
commit9a50168c85c691205b8e9606ca6db81c7d9ce482 (patch)
treef258247c97a6c2685e2e6ccfe156ec0119fac413
parent1d87b803f78309ba7a7e52452620098004b9d628 (diff)
Test config should use manifest package attribute
Bug: 70981774,69929803 Test: m -j SetupWizardActivityTests Change-Id: I6d50744504eac71d6ecae5db9b14e6d30eb923fe
-rwxr-xr-xtools/auto_gen_test_config.py12
-rw-r--r--tools/auto_gen_test_config_test.py17
2 files changed, 17 insertions, 12 deletions
diff --git a/tools/auto_gen_test_config.py b/tools/auto_gen_test_config.py
index fa018f4579..da4443c432 100755
--- a/tools/auto_gen_test_config.py
+++ b/tools/auto_gen_test_config.py
@@ -24,7 +24,7 @@ from xml.dom.minidom import parse
ATTRIBUTE_LABEL = 'android:label'
ATTRIBUTE_RUNNER = 'android:name'
-ATTRIBUTE_TARGET_PACKAGE = 'android:targetPackage'
+ATTRIBUTE_PACKAGE = 'package'
PLACEHOLDER_LABEL = '{LABEL}'
PLACEHOLDER_MODULE = '{MODULE}'
@@ -54,20 +54,22 @@ def main(argv):
manifest = parse(android_manifest)
instrumentation_elements = manifest.getElementsByTagName('instrumentation')
- if len(instrumentation_elements) != 1:
- # Failed to locate instrumentation element in AndroidManifest file.
- # Empty test config file will be created.
+ manifest_elements = manifest.getElementsByTagName('manifest')
+ if len(instrumentation_elements) != 1 or len(manifest_elements) != 1:
+ # Failed to locate instrumentation or manifest element in AndroidManifest.
+ # file. Empty test config file will be created.
shutil.copyfile(empty_config, target_config)
return 0
module = os.path.splitext(os.path.basename(target_config))[0]
instrumentation = instrumentation_elements[0]
+ manifest = manifest_elements[0]
if instrumentation.attributes.has_key(ATTRIBUTE_LABEL):
label = instrumentation.attributes[ATTRIBUTE_LABEL].value
else:
label = module
runner = instrumentation.attributes[ATTRIBUTE_RUNNER].value
- package = instrumentation.attributes[ATTRIBUTE_TARGET_PACKAGE].value
+ package = manifest.attributes[ATTRIBUTE_PACKAGE].value
test_type = ('AndroidJUnitTest' if runner.endswith('.AndroidJUnitRunner')
else 'InstrumentationTest')
diff --git a/tools/auto_gen_test_config_test.py b/tools/auto_gen_test_config_test.py
index a438b734a8..e70eff88ac 100644
--- a/tools/auto_gen_test_config_test.py
+++ b/tools/auto_gen_test_config_test.py
@@ -31,7 +31,8 @@ MANIFEST_INVALID = """<?xml version="1.0" encoding="utf-8"?>
"""
MANIFEST_JUNIT_TEST = """<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.my.tests.x">
<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:targetPackage="com.android.my.tests" />
@@ -39,7 +40,8 @@ MANIFEST_JUNIT_TEST = """<?xml version="1.0" encoding="utf-8"?>
"""
MANIFEST_INSTRUMENTATION_TEST = """<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.my.tests.x">
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.android.my.tests"
@@ -69,7 +71,7 @@ EXPECTED_JUNIT_TEST_CONFIG = """<?xml version="1.0" encoding="utf-8"?>
</target_preparer>
<test class="com.android.tradefed.testtype.AndroidJUnitTest" >
- <option name="package" value="com.android.my.tests" />
+ <option name="package" value="com.android.my.tests.x" />
<option name="runner" value="android.support.test.runner.AndroidJUnitRunner" />
</test>
</configuration>
@@ -97,16 +99,17 @@ EXPECTED_INSTRUMENTATION_TEST_CONFIG = """<?xml version="1.0" encoding="utf-8"?>
</target_preparer>
<test class="com.android.tradefed.testtype.InstrumentationTest" >
- <option name="package" value="com.android.my.tests" />
+ <option name="package" value="com.android.my.tests.x" />
<option name="runner" value="android.test.InstrumentationTestRunner" />
</test>
</configuration>
"""
-MAKE_ROOT = os.path.dirname(os.path.dirname(__file__))
-EMPTY_TEST_CONFIG = os.path.join(MAKE_ROOT, 'core', 'empty_test_config.xml')
+TOOLS_DIR = os.path.dirname(os.path.dirname(__file__))
+EMPTY_TEST_CONFIG = os.path.join(
+ TOOLS_DIR, '..', 'core', 'empty_test_config.xml')
INSTRUMENTATION_TEST_CONFIG_TEMPLATE = os.path.join(
- MAKE_ROOT, 'core', 'instrumentation_test_config_template.xml')
+ TOOLS_DIR, '..', 'core', 'instrumentation_test_config_template.xml')
class AutoGenTestConfigUnittests(unittest.TestCase):