Skip to content

Commit e5d93c0

Browse files
authored
Improved error message fallback logic (#35)
1 parent ee19af4 commit e5d93c0

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

ingest_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ func TestExamplesInTheWild(t *testing.T) {
131131
assert.Equal(t, testcase, suites[0].Tests[0])
132132
},
133133
},
134+
{
135+
title: "fastlane example",
136+
filename: "testdata/fastlane-trainer.xml",
137+
check: func(t *testing.T, suites []Suite) {
138+
assert.Len(t, suites, 1)
139+
assert.Len(t, suites[0].Tests, 4)
140+
141+
var testcase = Test{
142+
Name: "testSomething()",
143+
Classname: "TestClassSample",
144+
Duration: 342 * time.Millisecond,
145+
Status: StatusFailed,
146+
Error: Error{
147+
Message: "XCTAssertTrue failed",
148+
Body: "\n ",
149+
},
150+
Properties: map[string]string{
151+
"classname": "TestClassSample",
152+
"name": "testSomething()",
153+
"time": "0.342",
154+
},
155+
}
156+
157+
assert.Equal(t, testcase, suites[0].Tests[2])
158+
assert.EqualError(t, suites[0].Tests[2].Error, "XCTAssertTrue failed")
159+
assert.EqualError(t, suites[0].Tests[3].Error, "NullPointerException")
160+
},
161+
},
134162
}
135163

136164
for index, test := range tests {

testdata/fastlane-trainer.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites tests="4" failures="2">
3+
<testsuite name="UnitTests" tests="4" failures="2">
4+
<testcase classname="TestClass" name="testName()" time="0.45252">
5+
</testcase>
6+
<testcase classname="TestClass" name="testLaunch1()" time="0.2542">
7+
</testcase>
8+
<testcase classname="TestClassSample" name="testSomething()" time="0.342">
9+
<failure message="XCTAssertTrue failed">
10+
</failure>
11+
</testcase>
12+
<testcase classname="TestClassSample" name="testSomething2()" time="0.441">
13+
<failure type="NullPointerException">
14+
</failure>
15+
</testcase>
16+
</testsuite>
17+
</testsuites>

types.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
package junit
66

7-
import "time"
7+
import (
8+
"strings"
9+
"time"
10+
)
811

912
// Status represents the result of a single a JUnit testcase. Indicates if a
1013
// testcase was run, and if it was successful.
@@ -156,5 +159,14 @@ type Error struct {
156159

157160
// Error returns a textual description of the test error.
158161
func (err Error) Error() string {
159-
return err.Body
162+
switch {
163+
case strings.TrimSpace(err.Body) != "":
164+
return err.Body
165+
166+
case strings.TrimSpace(err.Message) != "":
167+
return err.Message
168+
169+
default:
170+
return err.Type
171+
}
160172
}

0 commit comments

Comments
 (0)