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