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

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

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: add tests 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_test.py
diff --git a/build/android/pylib/instrumentation/instrumentation_test_instance_test.py b/build/android/pylib/instrumentation/instrumentation_test_instance_test.py
index a0bf46493462bf29145d6ddc630cb783d35ec3ee..9faff2be60b70a005013a053f35c5fc24de530bf 100755
--- a/build/android/pylib/instrumentation/instrumentation_test_instance_test.py
+++ b/build/android/pylib/instrumentation/instrumentation_test_instance_test.py
@@ -145,8 +145,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -186,12 +187,118 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._test_filter = 'org.chromium.test.SampleTest.testMethod1'
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
+ def testGetTests_simpleGtestUnqualifiedNameFilter(self):
+ o = self.createTestInstance()
+ raw_tests = [
+ {
+ 'annotations': {'Feature': {'value': ['Foo']}},
+ 'class': 'org.chromium.test.SampleTest',
+ 'superclass': 'java.lang.Object',
+ 'methods': [
+ {
+ 'annotations': {'SmallTest': None},
+ 'method': 'testMethod1',
+ },
+ {
+ 'annotations': {'MediumTest': None},
+ 'method': 'testMethod2',
+ },
+ ],
+ }
+ ]
+
+ expected_tests = [
+ {
+ 'annotations': {
+ 'Feature': {'value': ['Foo']},
+ 'SmallTest': None,
+ },
+ 'class': 'org.chromium.test.SampleTest',
+ 'is_junit4': True,
+ 'method': 'testMethod1',
+ },
+ ]
+
+ o._test_filter = 'SampleTest.testMethod1'
+ o._test_jar = 'path/to/test.jar'
+ o._test_runner_junit4 = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
+ actual_tests = o.GetTests()
+
+ self.assertEquals(actual_tests, expected_tests)
+
+ def testGetTests_parameterizedTestGtestFilter(self):
+ o = self.createTestInstance()
+ raw_tests = [
+ {
+ 'annotations': {'Feature': {'value': ['Foo']}},
+ 'class': 'org.chromium.test.SampleTest',
+ 'superclass': 'java.lang.Object',
+ 'methods': [
+ {
+ 'annotations': {'SmallTest': None},
+ 'method': 'testMethod1',
+ },
+ {
+ 'annotations': {'SmallTest': None},
+ 'method': 'testMethod1__sandboxed_mode',
+ },
+ ],
+ },
+ {
+ 'annotations': {'Feature': {'value': ['Bar']}},
+ 'class': 'org.chromium.test.SampleTest2',
+ 'superclass': 'java.lang.Object',
+ 'methods': [
+ {
+ 'annotations': {'SmallTest': None},
+ 'method': 'testMethod1',
+ },
+ ],
+ }
+ ]
+
+ expected_tests = [
+ {
+ 'annotations': {
+ 'Feature': {'value': ['Foo']},
+ 'SmallTest': None,
+ },
+ 'class': 'org.chromium.test.SampleTest',
+ 'method': 'testMethod1',
+ 'is_junit4': True,
+ },
+ {
+ 'annotations': {
+ 'Feature': {'value': ['Foo']},
+ 'SmallTest': None,
+ },
+ 'class': 'org.chromium.test.SampleTest',
+ 'method': 'testMethod1__sandboxed_mode',
+ 'is_junit4': True,
+ },
+ ]
+
+ o._test_jar = 'path/to/test.jar'
+ o._test_runner_junit4 = 'J4Runner'
+ o._test_filter = 'org.chromium.test.SampleTest.testMethod1'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
+ actual_tests = o.GetTests()
+
+ self.assertEquals(actual_tests, expected_tests)
+
+
def testGetTests_wildcardGtestFilter(self):
o = self.createTestInstance()
raw_tests = [
@@ -238,8 +345,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._test_filter = 'org.chromium.test.SampleTest2.*'
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -299,8 +407,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._test_filter = '*-org.chromium.test.SampleTest.testMethod1'
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -360,8 +469,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._annotations = [('SmallTest', None)]
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -412,8 +522,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._excluded_annotations = [('SmallTest', None)]
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -474,8 +585,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._annotations = [('TestValue', '1')]
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -526,12 +638,76 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._annotations = [('Feature', 'Bar')]
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
+ def testGetTestName(self):
+ test = {'annotations': {
+ 'RunWith': {'value': 'class J4Runner'},
mikecase (-- gone --) 2017/07/18 23:59:12 intentation looks pretty weird here.
the real yoland 2017/07/19 00:12:49 Done
+ 'SmallTest': {},
+ 'Test': {'expected': 'class org.junit.Test$None',
+ 'timeout': '0'},
mikecase (-- gone --) 2017/07/18 23:59:12 extra space here.
the real yoland 2017/07/19 00:12:49 Done
+ 'UiThreadTest': {}},
+ 'class': 'org.chromium.TestA',
+ 'is_junit4': True,
+ 'method': 'testSimple'}
+ unqualified_class_test = {
+ 'class': test['class'].split('.')[-1],
+ 'method': test['method']
+ }
+
+ self.assertEquals(
+ instrumentation_test_instance.GetTestName(test, sep='.'),
+ 'org.chromium.TestA.testSimple')
+ self.assertEquals(
+ instrumentation_test_instance.GetTestName(
+ unqualified_class_test, sep='.'),
+ 'TestA.testSimple')
+
+ def testGetUniqueTestName(self):
+ test = {
+ 'annotations': {
+ 'RunWith': {'value': 'class J4Runner'},
+ 'SmallTest': {},
+ 'Test': {'expected': 'class org.junit.Test$None', 'timeout': '0'},
+ 'UiThreadTest': {}},
+ 'class': 'org.chromium.TestA',
+ 'flags': ['enable_features=abc'],
+ 'is_junit4': True,
+ 'method': 'testSimple'}
+ self.assertEquals(
+ instrumentation_test_instance.GetUniqueTestName(
+ test, sep='.'),
+ 'org.chromium.TestA.testSimple with enable_features=abc')
+
+ def testGetTestNameWithoutParameterPostfix(self):
+ test = {
+ 'annotations': {
+ 'RunWith': {'value': 'class J4Runner'},
+ 'SmallTest': {},
+ 'Test': {'expected': 'class org.junit.Test$None', 'timeout': '0'},
+ 'UiThreadTest': {}},
+ 'class': 'org.chromium.TestA__sandbox_mode',
+ 'flags': 'enable_features=abc',
+ 'is_junit4': True,
+ 'method': 'testSimple'}
+ unqualified_class_test = {
+ 'class': test['class'].split('.')[-1],
+ 'method': test['method']
+ }
+ self.assertEquals(
+ instrumentation_test_instance.GetTestNameWithoutParameterPostfix(
+ test, sep='.'),
+ 'org.chromium.TestA')
+ self.assertEquals(
+ instrumentation_test_instance.GetTestNameWithoutParameterPostfix(
+ unqualified_class_test, sep='.'),
+ 'TestA')
+
def testGetTests_multipleAnnotationValuesRequested(self):
o = self.createTestInstance()
raw_tests = [
@@ -590,8 +766,9 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
o._annotations = [('Feature', 'Bar'), ('Feature', 'Baz')]
o._test_jar = 'path/to/test.jar'
o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)

Powered by Google App Engine
This is Rietveld 408576698