1 # Copyright 2014 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.
9 from devil
.utils
import cmd_helper
10 from pylib
import constants
11 from pylib
.results
import json_results
13 class JavaTestRunner(object):
14 """Runs java tests on the host."""
16 def __init__(self
, args
):
17 self
._package
_filter
= args
.package_filter
18 self
._runner
_filter
= args
.runner_filter
19 self
._sdk
_version
= args
.sdk_version
20 self
._test
_filter
= args
.test_filter
21 self
._test
_suite
= args
.test_suite
26 def RunTest(self
, _test
):
27 """Runs junit tests from |self._test_suite|."""
28 with tempfile
.NamedTemporaryFile() as json_file
:
29 java_script
= os
.path
.join(
30 constants
.GetOutDirectory(), 'bin', self
._test
_suite
)
31 command
= [java_script
,
32 '-test-jars', self
._test
_suite
+ '.jar',
33 '-json-results-file', json_file
.name
]
35 command
.extend(['-gtest-filter', self
._test
_filter
])
36 if self
._package
_filter
:
37 command
.extend(['-package-filter', self
._package
_filter
])
38 if self
._runner
_filter
:
39 command
.extend(['-runner-filter', self
._runner
_filter
])
41 command
.extend(['-sdk-version', self
._sdk
_version
])
42 return_code
= cmd_helper
.RunCmd(command
)
43 results_list
= json_results
.ParseResultsFromJson(
44 json
.loads(json_file
.read()))
45 return (results_list
, return_code
)