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

Side by Side Diff: build/android/pylib/local/machine/local_machine_junit_test_run.py

Issue 2498553004: Add support for Junit tests in platform mode. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import json
6 import os
7 import tempfile
8
9 from devil.utils import cmd_helper
10 from pylib import constants
11 from pylib.base import base_test_result
12 from pylib.base import test_run
13 from pylib.results import json_results
14
15
16 class LocalMachineJunitTestRun(
17 test_run.TestRun):
jbudorick 2016/11/11 22:29:38 nit: this shouldn't be on its own line.
mikecase (-- gone --) 2016/11/11 22:51:35 Done
18 def __init__(self, env, test_instance):
19 super(LocalMachineJunitTestRun, self).__init__(env, test_instance)
20
21 #override
22 def TestPackage(self):
23 return self._test_instance.suite
24
25 #override
26 def SetUp(self):
27 pass
28
29 #override
30 def RunTests(self):
31 with tempfile.NamedTemporaryFile() as json_file:
32 java_script = os.path.join(
33 constants.GetOutDirectory(), 'bin', 'helper',
34 self._test_instance.suite)
35 command = [java_script]
36
37 # Add Jar arguments.
38 jar_args = ['-test-jars', self._test_instance.suite + '.jar',
39 '-json-results-file', json_file.name]
40 if self._test_instance.test_filter:
41 jar_args.extend(['-gtest-filter', self._test_instance.test_filter])
42 if self._test_instance.package_filter:
43 jar_args.extend(['-package-filter',
44 self._test_instance.package_filter])
45 if self._test_instance.runner_filter:
46 jar_args.extend(['-runner-filter', self._test_instance.runner_filter])
47 command.extend(['--jar-args', '"%s"' % ' '.join(jar_args)])
48
49 # Add JVM arguments.
50 jvm_args = []
51 # TODO(mikecase): Add a --robolectric-dep-dir arg to test runner.
52 # Have this arg set by GN in the generated test runner scripts.
53 jvm_args += [
54 '-Drobolectric.dependency.dir=%s' %
55 os.path.join(constants.GetOutDirectory(),
56 'lib.java', 'third_party', 'robolectric')]
57 if self._test_instance.coverage_dir:
58 if not os.path.exists(self._test_instance.coverage_dir):
59 os.makedirs(self._test_instance.coverage_dir)
60 elif not os.path.isdir(self._test_instance.coverage_dir):
61 raise Exception('--coverage-dir takes a directory, not file path.')
62 jvm_args.append('-Demma.coverage.out.file=%s' % os.path.join(
63 self._test_instance.coverage_dir,
64 '%s.ec' % self._test_instance.suite))
65 if jvm_args:
66 command.extend(['--jvm-args', '"%s"' % ' '.join(jvm_args)])
67
68 cmd_helper.RunCmd(command)
69 results_list = json_results.ParseResultsFromJson(
70 json.loads(json_file.read()))
71
72 test_run_results = base_test_result.TestRunResults()
73 test_run_results.AddResults(results_list)
74
75 return [test_run_results]
76
77 #override
78 def TearDown(self):
79 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698