Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Unified Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 2991833003: Revert of List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/instrumentation/instrumentation_test_instance.py
diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance.py b/build/android/pylib/instrumentation/instrumentation_test_instance.py
index 4bb0770ab0c110a5497b34f020d989a40ad9c071..cb5d691f33fd4c07c189faf92606617e1a7e3827 100644
--- a/build/android/pylib/instrumentation/instrumentation_test_instance.py
+++ b/build/android/pylib/instrumentation/instrumentation_test_instance.py
@@ -36,14 +36,6 @@
'DisabledTest', 'FlakyTest']
_VALID_ANNOTATIONS = set(['Manual'] + _DEFAULT_ANNOTATIONS +
_EXCLUDE_UNLESS_REQUESTED_ANNOTATIONS)
-
-# These test methods are inherited from android.test base test class and
-# should be permitted for not having size annotation. For more, please check
-# https://developer.android.com/reference/android/test/AndroidTestCase.html
-# https://developer.android.com/reference/android/test/ServiceTestCase.html
-_TEST_WITHOUT_SIZE_ANNOTATIONS = [
- 'testAndroidTestCaseSetupProperly', 'testServiceTestCaseSetUpProperly']
-
_EXTRA_DRIVER_TEST_LIST = (
'org.chromium.test.driver.OnDeviceInstrumentationDriver.TestList')
_EXTRA_DRIVER_TEST_LIST_FILE = (
@@ -75,7 +67,7 @@
# TODO(jbudorick): Make these private class methods of
-# InstrumentationTestInstance once the instrumentation junit3_runner_class is
+# InstrumentationTestInstance once the instrumentation test_runner is
# deprecated.
def ParseAmInstrumentRawOutput(raw_output):
"""Parses the output of an |am instrument -r| call.
@@ -171,8 +163,8 @@
Args:
tests: a list of tests. e.g. [
- {'annotations": {}, 'class': 'com.example.TestA', 'method':'test1'},
- {'annotations": {}, 'class': 'com.example.TestB', 'method':'test2'}]
+ {'annotations": {}, 'class': 'com.example.TestA', 'methods':[]},
+ {'annotations": {}, 'class': 'com.example.TestB', 'methods':[]}]
test_filter: googletest-style filter string.
annotations: a dict of wanted annotations for test methods.
exclude_annotations: a dict of annotations to exclude.
@@ -194,12 +186,6 @@
GetUniqueTestName(t, sep='.')
]
- if t['is_junit4']:
- names += [
- GetTestNameWithoutParameterPostfix(t, sep='.'),
- GetTestNameWithoutParameterPostfix(unqualified_class_test, sep='.')
- ]
-
pattern_groups = test_filter.split('-')
if len(pattern_groups) > 1:
negative_filter = pattern_groups[1]
@@ -242,8 +228,7 @@
continue
# Enforce that all tests declare their size.
- if (not any(a in _VALID_ANNOTATIONS for a in t['annotations'])
- and t['method'] not in _TEST_WITHOUT_SIZE_ANNOTATIONS):
+ if not any(a in _VALID_ANNOTATIONS for a in t['annotations']):
raise MissingSizeAnnotationError(GetTestName(t))
if (not annotation_filter(t['annotations'])
@@ -255,31 +240,30 @@
return filtered_tests
-# TODO(yolandyan): remove this once the tests are converted to junit4
def GetAllTestsFromJar(test_jar):
pickle_path = '%s-proguard.pickle' % test_jar
try:
- tests = GetTestsFromPickle(pickle_path, test_jar)
+ tests = _GetTestsFromPickle(pickle_path, test_jar)
except TestListPickleException as e:
logging.info('Could not get tests from pickle: %s', e)
logging.info('Getting tests from JAR via proguard.')
tests = _GetTestsFromProguard(test_jar)
- SaveTestsToPickle(pickle_path, test_jar, tests)
+ _SaveTestsToPickle(pickle_path, test_jar, tests)
return tests
def GetAllTestsFromApk(test_apk):
pickle_path = '%s-dexdump.pickle' % test_apk
try:
- tests = GetTestsFromPickle(pickle_path, test_apk)
+ tests = _GetTestsFromPickle(pickle_path, test_apk)
except TestListPickleException as e:
logging.info('Could not get tests from pickle: %s', e)
logging.info('Getting tests from dex via dexdump.')
tests = _GetTestsFromDexdump(test_apk)
- SaveTestsToPickle(pickle_path, test_apk, tests)
+ _SaveTestsToPickle(pickle_path, test_apk, tests)
return tests
-def GetTestsFromPickle(pickle_path, jar_path):
+def _GetTestsFromPickle(pickle_path, jar_path):
if not os.path.exists(pickle_path):
raise TestListPickleException('%s does not exist.' % pickle_path)
if os.path.getmtime(pickle_path) <= os.path.getmtime(jar_path):
@@ -354,7 +338,8 @@
})
return tests
-def SaveTestsToPickle(pickle_path, jar_path, tests):
+
+def _SaveTestsToPickle(pickle_path, jar_path, tests):
jar_md5 = md5sum.CalculateHostMd5Sums(jar_path)[jar_path]
pickle_data = {
'VERSION': _PICKLE_FORMAT_VERSION,
@@ -394,28 +379,6 @@
The test name as a string.
"""
return '%s%s%s' % (test['class'], sep, test['method'])
-
-
-def GetTestNameWithoutParameterPostfix(
- test, sep='#', parameterization_sep='__'):
- """Gets the name of the given JUnit4 test without parameter postfix.
-
- For most WebView JUnit4 javatests, each test is parameterizatized with
- "__sandboxed_mode" to run in both non-sandboxed mode and sandboxed mode.
-
- This function returns the name of the test without parameterization
- so test filters can match both parameterized and non-parameterized tests.
-
- Args:
- test: the instrumentation test dict.
- sep: the character(s) that should join the class name and the method name.
- parameterization_sep: the character(s) that seperate method name and method
- parameterization postfix.
- Returns:
- The test name without parameter postfix as a string.
- """
- name = GetTestName(test, sep=sep)
- return name.split(parameterization_sep)[0]
def GetUniqueTestName(test, sep='#'):
@@ -450,8 +413,8 @@
self._test_apk_incremental_install_script = None
self._test_jar = None
self._test_package = None
- self._junit3_runner_class = None
- self._junit4_runner_class = None
+ self._test_runner = None
+ self._test_runner_junit4 = None
self._test_support_apk = None
self._initializeApkAttributes(args, error_func)
@@ -558,25 +521,23 @@
self._test_package = self._test_apk.GetPackageName()
all_instrumentations = self._test_apk.GetAllInstrumentations()
- all_junit3_runner_classes = [
+ test_runners = [
x for x in all_instrumentations if ('true' not in x.get(
'chromium-junit4', ''))]
- all_junit4_test_runner_classes = [
+ test_runners_junit4 = [
x for x in all_instrumentations if ('true' in x.get(
'chromium-junit4', ''))]
- if len(all_junit3_runner_classes) > 1:
+ if len(test_runners) > 1:
logging.warning('This test apk has more than one JUnit3 instrumentation')
- if len(all_junit4_test_runner_classes) > 1:
+ if len(test_runners_junit4) > 1:
logging.warning('This test apk has more than one JUnit4 instrumentation')
- self._junit3_runner_class = (
- all_junit3_runner_classes[0]['android:name']
- if all_junit3_runner_classes else self.test_apk.GetInstrumentationName())
-
- self._junit4_runner_class = (
- all_junit4_test_runner_classes[0]['android:name']
- if all_junit4_test_runner_classes else None)
+ self._test_runner = (
+ test_runners[0]['android:name'] if test_runners else
+ self.test_apk.GetInstrumentationName())
+ self._test_runner_junit4 = (
+ test_runners_junit4[0]['android:name'] if test_runners_junit4 else None)
self._package_info = None
if self._apk_under_test:
@@ -730,14 +691,6 @@
return self._gs_results_bucket
@property
- def junit3_runner_class(self):
- return self._junit3_runner_class
-
- @property
- def junit4_runner_class(self):
- return self._junit4_runner_class
-
- @property
def should_save_logcat(self):
return self._should_save_logcat
@@ -784,6 +737,14 @@
@property
def test_package(self):
return self._test_package
+
+ @property
+ def test_runner(self):
+ return self._test_runner
+
+ @property
+ def test_runner_junit4(self):
+ return self._test_runner_junit4
@property
def timeout_scale(self):
@@ -811,15 +772,11 @@
def GetTests(self):
if self.test_jar:
- raw_tests = GetAllTestsFromJar(self.test_jar)
+ tests = GetAllTestsFromJar(self.test_jar)
else:
- raw_tests = GetAllTestsFromApk(self.test_apk.path)
- return self.ProcessRawTests(raw_tests)
-
- def ProcessRawTests(self, raw_tests):
- inflated_tests = self._ParameterizeTestsWithFlags(
- self._InflateTests(raw_tests))
- if self._junit4_runner_class is None and any(
+ tests = GetAllTestsFromApk(self.test_apk.path)
+ inflated_tests = self._ParameterizeTestsWithFlags(self._InflateTests(tests))
+ if self._test_runner_junit4 is None and any(
t['is_junit4'] for t in inflated_tests):
raise MissingJUnit4RunnerException()
filtered_tests = FilterTests(
@@ -866,7 +823,7 @@
self, test_list=None, test_list_file_path=None):
env = {
_EXTRA_DRIVER_TARGET_PACKAGE: self.test_package,
- _EXTRA_DRIVER_TARGET_CLASS: self.junit3_runner_class,
+ _EXTRA_DRIVER_TARGET_CLASS: self.test_runner,
_EXTRA_TIMEOUT_SCALE: self._timeout_scale,
}

Powered by Google App Engine
This is Rietveld 408576698