def __RunJavaTest(self, test, test_pkg, additional_flags=None): """Runs a single Java test in a Java TestRunner. Args: test: Fully qualified test name (ex. foo.bar.TestClass#testMethod) test_pkg: TestPackage object. additional_flags: A list of additional flags to add to the command line. Returns: TestRunResults object with a single test result. """ # TODO(bulach): move this to SetUp() stage. self.__StartForwarder() java_test_runner = test_runner.TestRunner( self.instrumentation_options, self.device_id, self.shard_index, test_pkg, additional_flags=additional_flags) try: java_test_runner.SetUp() return java_test_runner.RunTest(test)[0] finally: java_test_runner.TearDown()
def _RunJavaTest(self, fname, suite, test): """Runs a single Java test with a Java TestRunner. Args: fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) suite: name of the Java test suite (e.g. FooTest) test: name of the test method to run (e.g. testFooBar) Returns: TestRunResults object with a single test result. """ test = self._ComposeFullTestName(fname, suite, test) test_pkg = test_package.TestPackage(self.options.test_apk_path, self.options.test_apk_jar_path) instrumentation_options = test_options.InstrumentationOptions( self.options.build_type, self.options.tool, self.options.cleanup_test_files, self.options.push_deps, self.options.annotations, self.options.exclude_annotations, self.options.test_filter, self.options.test_data, self.options.save_perf_json, self.options.screenshot_failures, self.options.disable_assertions, self.options.wait_for_debugger, self.options.test_apk, self.options.test_apk_path, self.options.test_apk_jar_path) java_test_runner = test_runner.TestRunner(instrumentation_options, self.device_id, self.shard_index, test_pkg, self.ports_to_forward) try: java_test_runner.SetUp() return java_test_runner.RunTest(test)[0] finally: java_test_runner.TearDown()
def __RunJavaTest(self, package_name, test_case, test_method): """Runs a single Java test method with a Java TestRunner. Args: package_name: Package name in which the java tests live (e.g. foo.bar.baz.tests) test_case: Name of the Java test case (e.g. FooTest) test_method: Name of the test method to run (e.g. testFooBar) Returns: TestRunResults object with a single test result. """ test = '%s.%s#%s' % (package_name, test_case, test_method) test_pkg = test_package.TestPackage( self.instrumentation_options.test_apk_path, self.instrumentation_options.test_apk_jar_path) java_test_runner = test_runner.TestRunner(self.instrumentation_options, self.device_id, self.shard_index, test_pkg, self.ports_to_forward) try: java_test_runner.SetUp() return java_test_runner.RunTest(test)[0] finally: java_test_runner.TearDown()
def RunJavaTest(fname, suite, test, ports_to_forward): device = android_commands.GetAttachedDevices()[0] package_name = _GetPackageName(fname) test = package_name + '.' + suite + '#' + test java_test_runner = test_runner.TestRunner(False, device, [test], False, False, False, False, 0, ports_to_forward) return java_test_runner.Run()
def DispatchPythonTests(options): """Dispatches the Python tests. If there are multiple devices, use sharding. Args: options: command line options. Returns: A list of test results. """ attached_devices = android_commands.GetAttachedDevices() if not attached_devices: raise Exception('You have no devices attached or visible!') if options.device: attached_devices = [options.device] test_collection = TestInfoCollection() all_tests = _GetAllTests(options.python_test_root, options.official_build) test_collection.AddTests(all_tests) test_names = [t.qualified_name for t in all_tests] logging.debug('All available tests: ' + str(test_names)) available_tests = test_collection.GetAvailableTests( options.annotations, options.exclude_annotations, options.test_filter) if not available_tests: logging.warning('No Python tests to run with current args.') return base_test_result.TestRunResults() test_names = [t.qualified_name for t in available_tests] logging.debug('Final list of tests to run: ' + str(test_names)) # Copy files to each device before running any tests. for device_id in attached_devices: logging.debug('Pushing files to device %s', device_id) test_pkg = test_package.TestPackage(options.test_apk_path, options.test_apk_jar_path) test_files_copier = test_runner.TestRunner(options, device_id, 0, test_pkg, []) test_files_copier.InstallTestPackage() if options.push_deps: logging.info('Pushing data deps to device.') test_files_copier.PushDataDeps() else: logging.warning('Skipping pushing data deps to device.') # Actually run the tests. if len(attached_devices) > 1 and options.wait_for_debugger: logging.warning('Debugger can not be sharded, ' 'using first available device') attached_devices = attached_devices[:1] logging.debug('Running Python tests') sharder = PythonTestSharder(attached_devices, available_tests, options) test_results = sharder.RunShardedTests() return test_results
def DispatchPythonTests(options): """Dispatches the Python tests. If there are multiple devices, use sharding. Args: options: command line options. Returns: A list of test results. """ attached_devices = android_commands.GetAttachedDevices() if not attached_devices: raise Exception('You have no devices attached or visible!') if options.device: attached_devices = [options.device] test_collection = TestInfoCollection() all_tests = _GetAllTests(options.python_test_root, options.official_build) test_collection.AddTests(all_tests) test_names = [t.qualified_name for t in all_tests] logging.debug('All available tests: ' + str(test_names)) available_tests = test_collection.GetAvailableTests( options.annotation, options.test_filter) if not available_tests: logging.warning('No Python tests to run with current args.') return TestResults() available_tests *= options.number_of_runs test_names = [t.qualified_name for t in available_tests] logging.debug('Final list of tests to run: ' + str(test_names)) # Copy files to each device before running any tests. for device_id in attached_devices: logging.debug('Pushing files to device %s', device_id) apks = [ apk_info.ApkInfo(options.test_apk_path, options.test_apk_jar_path) ] test_files_copier = test_runner.TestRunner(options, device_id, None, False, 0, apks, []) test_files_copier.CopyTestFilesOnce() # Actually run the tests. if len(attached_devices) > 1 and options.wait_for_debugger: logging.warning('Debugger can not be sharded, ' 'using first available device') attached_devices = attached_devices[:1] logging.debug('Running Python tests') sharder = PythonTestSharder(attached_devices, available_tests, options) test_results = sharder.RunShardedTests() return test_results
def _RunJavaTest(self, fname, suite, test): """Runs a single Java test with a Java TestRunner. Args: fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) suite: name of the Java test suite (e.g. FooTest) test: name of the test method to run (e.g. testFooBar) Returns: TestResults object with a single test result. """ test = self._ComposeFullTestName(fname, suite, test) apks = [ apk_info.ApkInfo(self.options.test_apk_path, self.options.test_apk_jar_path) ] java_test_runner = test_runner.TestRunner(self.options, self.device_id, [test], False, self.shard_index, apks, self.ports_to_forward) return java_test_runner.Run()
def _RunJavaTest(self, fname, suite, test): """Runs a single Java test with a Java TestRunner. Args: fname: filename for the test (e.g. foo/bar/baz/tests/FooTest.py) suite: name of the Java test suite (e.g. FooTest) test: name of the test method to run (e.g. testFooBar) Returns: TestRunResults object with a single test result. """ test = self._ComposeFullTestName(fname, suite, test) test_pkg = test_package.TestPackage(self.options.test_apk_path, self.options.test_apk_jar_path) java_test_runner = test_runner.TestRunner(self.options, self.device_id, self.shard_index, test_pkg, self.ports_to_forward) try: java_test_runner.SetUp() return java_test_runner.RunTest(test)[0] finally: java_test_runner.TearDown()
def TestRunnerFactory(device, shard_index): return test_runner.TestRunner(test_options, device, shard_index, test_pkg)
def setUp(self): options = mock.Mock() options.tool = '' package = mock.Mock() self.instance = test_runner.TestRunner(options, '123456789abcdef0', 0, package)
def setUp(self): options = mock.Mock() options.tool = '' package = mock.Mock() self.instance = test_runner.TestRunner(options, None, 0, package)