OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 host-driven test cases. | 5 """Base class for host-driven test cases. |
6 | 6 |
7 This test case is intended to serve as the base class for any host-driven | 7 This test case is intended to serve as the base class for any host-driven |
8 test cases. It is similar to the Python unitttest module in that test cases | 8 test cases. It is similar to the Python unitttest module in that test cases |
9 inherit from this class and add methods which will be run as tests. | 9 inherit from this class and add methods which will be run as tests. |
10 | 10 |
11 When a HostDrivenTestCase object is instantiated, its purpose is to run only one | 11 When a HostDrivenTestCase object is instantiated, its purpose is to run only one |
12 test method in the derived class. The test runner gives it the name of the test | 12 test method in the derived class. The test runner gives it the name of the test |
13 method the instance will run. The test runner calls SetUp with the device ID | 13 method the instance will run. The test runner calls SetUp with the device ID |
14 which the test method will run against. The test runner runs the test method | 14 which the test method will run against. The test runner runs the test method |
15 itself, collecting the result, and calls TearDown. | 15 itself, collecting the result, and calls TearDown. |
16 | 16 |
17 Tests can perform arbitrary Python commands and asserts in test methods. Tests | 17 Tests can perform arbitrary Python commands and asserts in test methods. Tests |
18 that run instrumentation tests can make use of the _RunJavaTests helper function | 18 that run instrumentation tests can make use of the _RunJavaTestFilters helper |
19 to trigger Java tests and convert results into a single host-driven test result. | 19 function to trigger Java tests and convert results into a single host-driven |
| 20 test result. |
20 """ | 21 """ |
21 | 22 |
22 import logging | 23 import logging |
23 import os | 24 import os |
24 import time | 25 import time |
25 | 26 |
26 from pylib import android_commands | 27 from pylib import android_commands |
27 from pylib import constants | 28 from pylib import constants |
28 from pylib.base import base_test_result | 29 from pylib.base import base_test_result |
29 from pylib.instrumentation import test_package | 30 from pylib.instrumentation import test_package |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 java_test_runner = test_runner.TestRunner(self.instrumentation_options, | 90 java_test_runner = test_runner.TestRunner(self.instrumentation_options, |
90 self.device_id, | 91 self.device_id, |
91 self.shard_index, test_pkg, | 92 self.shard_index, test_pkg, |
92 self.ports_to_forward) | 93 self.ports_to_forward) |
93 try: | 94 try: |
94 java_test_runner.SetUp() | 95 java_test_runner.SetUp() |
95 return java_test_runner.RunTest(test)[0] | 96 return java_test_runner.RunTest(test)[0] |
96 finally: | 97 finally: |
97 java_test_runner.TearDown() | 98 java_test_runner.TearDown() |
98 | 99 |
99 # TODO(gkanwar): Remove old method once downstream tests are updated | |
100 def _RunJavaTests(self, package_name, tests): | |
101 """Calls a list of tests and stops at the first test failure.""" | |
102 return self._RunJavaTestFilters(tests) | |
103 | |
104 def _RunJavaTestFilters(self, test_filters): | 100 def _RunJavaTestFilters(self, test_filters): |
105 """Calls a list of tests and stops at the first test failure. | 101 """Calls a list of tests and stops at the first test failure. |
106 | 102 |
107 This method iterates until either it encounters a non-passing test or it | 103 This method iterates until either it encounters a non-passing test or it |
108 exhausts the list of tests. Then it returns the appropriate overall result. | 104 exhausts the list of tests. Then it returns the appropriate overall result. |
109 | 105 |
110 Test cases may make use of this method internally to assist in running | 106 Test cases may make use of this method internally to assist in running |
111 instrumentation tests. This function relies on instrumentation_options | 107 instrumentation tests. This function relies on instrumentation_options |
112 being defined. | 108 being defined. |
113 | 109 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 overall_result.AddResult( | 148 overall_result.AddResult( |
153 test_result.InstrumentationTestResult( | 149 test_result.InstrumentationTestResult( |
154 self.tagged_name, test_type, start_ms, duration_ms, log=log)) | 150 self.tagged_name, test_type, start_ms, duration_ms, log=log)) |
155 return overall_result | 151 return overall_result |
156 | 152 |
157 def __str__(self): | 153 def __str__(self): |
158 return self.tagged_name | 154 return self.tagged_name |
159 | 155 |
160 def __repr__(self): | 156 def __repr__(self): |
161 return self.tagged_name | 157 return self.tagged_name |
OLD | NEW |