Fix JUnit test-cases with error misclassified as passed test

Previous implementation considered only test-cases with <failure> as failed. This fix makes processing of <error> and <failure> the same. It also handles situation when error or failure elements contains only text and no attributes.
This commit is contained in:
Michal Dorner 2021-05-24 15:01:47 +02:00
parent 6969ae6af5
commit d01ef000ba
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
4 changed files with 25 additions and 12 deletions

View file

@ -107,18 +107,24 @@ export class JavaJunitParser implements TestParser {
}
private getTestCaseResult(test: TestCase): TestExecutionResult {
if (test.failure) return 'failed'
if (test.failure || test.error) return 'failed'
if (test.skipped) return 'skipped'
return 'success'
}
private getTestCaseError(tc: TestCase): TestCaseError | undefined {
if (!this.options.parseErrors || !tc.failure) {
if (!this.options.parseErrors) {
return undefined
}
const failure = tc.failure[0]
const details = failure._
// We process <error> and <failure> the same way
const failures = tc.failure ?? tc.error
if (!failures) {
return undefined
}
const failure = failures[0]
const details = typeof failure === 'object' ? failure._ : failure
let filePath
let line
@ -132,7 +138,7 @@ export class JavaJunitParser implements TestParser {
path: filePath,
line,
details,
message: failure.message
message: typeof failure === 'object' ? failure.message : undefined
}
}

View file

@ -33,7 +33,8 @@ export interface TestCase {
name: string
time: string
}
failure?: Failure[]
failure?: string | Failure[]
error?: string | Failure[]
skipped?: string[]
}