OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Base class for Android Python-driven tests. | 5 """Base class for Android Python-driven tests. |
6 | 6 |
7 This test case is intended to serve as the base class for any Python-driven | 7 This test case is intended to serve as the base class for any Python-driven |
8 tests. It is similar to the Python unitttest module in that the user's tests | 8 tests. It is similar to the Python unitttest module in that the user's tests |
9 inherit from this case and add their tests in that case. | 9 inherit from this case and add their tests in that case. |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 suite: name of the Java test suite (e.g. FooTest) | 71 suite: name of the Java test suite (e.g. FooTest) |
72 test: name of the test method to run (e.g. testFooBar) | 72 test: name of the test method to run (e.g. testFooBar) |
73 | 73 |
74 Returns: | 74 Returns: |
75 TestResults object with a single test result. | 75 TestResults object with a single test result. |
76 """ | 76 """ |
77 test = self._ComposeFullTestName(fname, suite, test) | 77 test = self._ComposeFullTestName(fname, suite, test) |
78 apks = [apk_info.ApkInfo(self.options.test_apk_path, | 78 apks = [apk_info.ApkInfo(self.options.test_apk_path, |
79 self.options.test_apk_jar_path)] | 79 self.options.test_apk_jar_path)] |
80 java_test_runner = test_runner.TestRunner(self.options, self.device_id, | 80 java_test_runner = test_runner.TestRunner(self.options, self.device_id, |
81 [test], False, self.shard_index, | 81 self.shard_index, False, apks, |
82 apks, self.ports_to_forward) | 82 self.ports_to_forward) |
83 return java_test_runner.Run() | 83 try: |
| 84 java_test_runner.SetUp() |
| 85 return java_test_runner.RunTest(test)[0] |
| 86 finally: |
| 87 java_test_runner.TearDown() |
84 | 88 |
85 def _RunJavaTests(self, fname, tests): | 89 def _RunJavaTests(self, fname, tests): |
86 """Calls a list of tests and stops at the first test failure. | 90 """Calls a list of tests and stops at the first test failure. |
87 | 91 |
88 This method iterates until either it encounters a non-passing test or it | 92 This method iterates until either it encounters a non-passing test or it |
89 exhausts the list of tests. Then it returns the appropriate Python result. | 93 exhausts the list of tests. Then it returns the appropriate Python result. |
90 | 94 |
91 Args: | 95 Args: |
92 fname: filename for the Python test | 96 fname: filename for the Python test |
93 tests: a list of Java test names which will be run | 97 tests: a list of Java test names which will be run |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 166 |
163 def _ComposeFullTestName(self, fname, suite, test): | 167 def _ComposeFullTestName(self, fname, suite, test): |
164 package_name = self._GetPackageName(fname) | 168 package_name = self._GetPackageName(fname) |
165 return package_name + '.' + suite + '#' + test | 169 return package_name + '.' + suite + '#' + test |
166 | 170 |
167 def _GetPackageName(self, fname): | 171 def _GetPackageName(self, fname): |
168 """Extracts the package name from the test file path.""" | 172 """Extracts the package name from the test file path.""" |
169 dirname = os.path.dirname(fname) | 173 dirname = os.path.dirname(fname) |
170 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] | 174 package = dirname[dirname.rfind(BASE_ROOT) + len(BASE_ROOT):] |
171 return package.replace(os.sep, '.') | 175 return package.replace(os.sep, '.') |
OLD | NEW |