PythonUnitTestResultParser
public
class
PythonUnitTestResultParser
extends MultiLineReceiver
| java.lang.Object | ||
| ↳ | com.android.ddmlib.MultiLineReceiver | |
| ↳ | com.android.tradefed.testtype.PythonUnitTestResultParser | |
Diễn giải kết quả của các bài kiểm thử chạy bằng khung unittest của Python và dịch kết quả đó thành các lệnh gọi trên một loạt ITestInvocationListener. Kết quả đầu ra của các kiểm thử này tuân theo ngữ pháp EBNF sau:
TestReport ::= TestResult* Line TimeMetric [FailMessage*] Status. TestResult ::= string \u201c(\u201cstring\u201d)\u201d \u201c\u2026\u201d SingleStatus. FailMessage ::= EqLine \u201cERROR:\u201d string \u201c(\u201cstring\u201d)\u201d Line Traceback Line. SingleStatus ::= \u201cok\u201d | \u201cERROR\u201d. TimeMetric ::= \u201cRan\u201d integer \u201ctests in\u201d float \u201ds\u201d. Status ::= \u201cOK\u201d | \u201cFAILED (errors=\u201d int \u201c)\u201d. Traceback ::= string+.
Ví dụ về đầu ra (đạt): test_size (test_rangelib.RangeSetTest) ... ok test_str (test_rangelib.RangeSetTest) ... ok test_subtract (test_rangelib.RangeSetTest) ... ok test_to_string_raw (test_rangelib.RangeSetTest) ... ok test_union (test_rangelib.RangeSetTest) ... ok
---------------------------------------------------------------------- Ran 5 tests in 0.002s
OK
Ví dụ về kết quả đầu ra (không thành công) test_size (test_rangelib.RangeSetTest) ... ERROR
====================================================================== ERROR: test_size (test_rangelib.RangeSetTest) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_rangelib.py", line 129, in test_rangelib raise ValueError() ValueError ---------------------------------------------------------------------- Ran 1 test in 0.001s FAILED (errors=1)
Ví dụ về đầu ra với một số trường hợp đặc biệt (không thành công): testError (foo.testFoo) ... ERROR testExpectedFailure (foo.testFoo) ... expected failure testFail (foo.testFoo) ... FAIL testFailWithDocString (foo.testFoo) foo bar ... FAIL testOk (foo.testFoo) ... ok testOkWithDocString (foo.testFoo) foo bar ... ok testSkipped (foo.testFoo) ... skipped 'reason foo' testUnexpectedSuccess (foo.testFoo) ... unexpected success
====================================================================== LỖI: testError (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 11, in testError self.assertEqual(2+2, 5/0) ZeroDivisionError: integer division or modulo by zero
====================================================================== FAIL: testFail (foo.testFoo) ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 8, in testFail self.assertEqual(2+2, 5) AssertionError: 4 != 5
===================================================================== FAIL: testFailWithDocString (foo.testFoo) foo bar ---------------------------------------------------------------------- Traceback (most recent call last): File "foo.py", line 31, in testFailWithDocString self.assertEqual(2+2, 5) AssertionError: 4 != 5
---------------------------------------------------------------------- Ran 8 tests in 0.001s
KHÔNG THÀNH CÔNG (failures=2, errors=1, skipped=1, expected failures=1, unexpected successes=1)
TODO: Cân nhắc tái cấu trúc toàn bộ lớp, việc xử lý hiện khá lộn xộn.
Tóm tắt
Hàm khởi tạo công khai | |
|---|---|
PythonUnitTestResultParser(
Tạo một |
|
PythonUnitTestResultParser(
Tạo một |
|
Phương thức công khai | |
|---|---|
void
|
finalizeParser()
|
boolean
|
isCancelled()
|
void
|
processNewLines(String[] lines)
Xử lý đầu ra của unittest Python và báo cáo kết quả đã phân tích cú pháp. |
void
|
setFinalizeWhenParsing(boolean shouldFinalize)
|
Hàm khởi tạo công khai
PythonUnitTestResultParser
public PythonUnitTestResultParser (listeners, String runName)
Tạo một PythonUnitTestResultParser mới báo cáo cho ITestInvocationListener đã cho.
| Tham số | |
|---|---|
listeners |
|
runName |
String |
PythonUnitTestResultParser
public PythonUnitTestResultParser (listeners, String runName, includeFilters, excludeFilters)
Tạo một PythonUnitTestResultParser mới báo cáo cho ITestInvocationListener đã cho, với các bộ lọc bao gồm và loại trừ được chỉ định.
| Tham số | |
|---|---|
listeners |
|
runName |
String |
includeFilters |
|
excludeFilters |
|
Phương thức công khai
finalizeParser
public void finalizeParser ()
isCancelled
public boolean isCancelled ()
| Giá trị trả về | |
|---|---|
boolean |
|
processNewLines
public void processNewLines (String[] lines)
Xử lý đầu ra của unittest Python và báo cáo kết quả đã phân tích cú pháp.
Bạn chỉ nên gọi phương thức này một lần với toàn bộ đầu ra, không giống như phương thức cơ sở trong MultiLineReceiver.
| Tham số | |
|---|---|
lines |
String: Mảng chứa các dòng mới. |
setFinalizeWhenParsing
public void setFinalizeWhenParsing (boolean shouldFinalize)
| Tham số | |
|---|---|
shouldFinalize |
boolean |