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

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

Issue 2935503002: List Java Instru Test Information From JUnit Runner (Closed)
Patch Set: compiling error fix 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 a71095dc82fb49e9a909f5b18c6e3c46131aadec..80ab993c0abb6189736c00e4d7f2304650bdb66c 100755
--- a/build/android/pylib/instrumentation/instrumentation_test_instance_test.py
+++ b/build/android/pylib/instrumentation/instrumentation_test_instance_test.py
@@ -144,9 +144,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -185,9 +186,114 @@ 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):
+ o._junit4_runner_class = '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_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._junit4_runner_class = '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._junit4_runner_class = '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)
@@ -237,9 +343,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -298,9 +405,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -359,9 +467,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -411,9 +520,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -473,9 +583,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -525,13 +636,78 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ 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'},
+ 'SmallTest': {},
+ 'Test': {'expected': 'class org.junit.Test$None',
+ 'timeout': '0'},
+ '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 = [
@@ -589,9 +765,10 @@ 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):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -764,9 +941,10 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
'method': 'testMethod2'}]
o._test_jar = 'path/to/test.jar'
- o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ o._junit4_runner_class = 'J4Runner'
+ with mock.patch(
+ _INSTRUMENTATION_TEST_INSTANCE_PATH % 'GetAllTestsFromRunner',
+ return_value=raw_tests):
actual_tests = o.GetTests()
self.assertEquals(actual_tests, expected_tests)
@@ -820,9 +998,10 @@ class InstrumentationTestInstanceTest(unittest.TestCase):
'method': 'testMethod2'}]
o._test_jar = 'path/to/test.jar'
- o._test_runner_junit4 = 'J4Runner'
- with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
- return_value=raw_tests):
+ o._junit4_runner_class = 'J4Runner'
+ 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