Skip to content

Commit 815a5b8

Browse files
committed
Improved examples in the readme
1 parent aced827 commit 815a5b8

File tree

1 file changed

+65
-34
lines changed

1 file changed

+65
-34
lines changed

README.md

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,81 @@ The simplest of which parses raw JUnit XML data.
2525

2626
```go
2727
xml := []byte(`
28-
<?xml version="1.0" encoding="UTF-8"?>
29-
<testsuites>
30-
<testsuite name="JUnitXmlReporter" errors="0" tests="0" failures="0" time="0" timestamp="2013-05-24T10:23:58" />
31-
<testsuite name="JUnitXmlReporter.constructor" errors="0" skipped="1" tests="3" failures="1" time="0.006" timestamp="2013-05-24T10:23:58">
32-
<properties>
33-
<property name="java.vendor" value="Sun Microsystems Inc." />
34-
<property name="compiler.debug" value="on" />
35-
<property name="project.jdk.classpath" value="jdk.classpath.1.6" />
36-
</properties>
37-
<testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006">
38-
<failure message="test failure">Assertion failed</failure>
39-
</testcase>
40-
<testcase classname="JUnitXmlReporter.constructor" name="should default consolidate to true" time="0">
41-
<skipped />
42-
</testcase>
43-
<testcase classname="JUnitXmlReporter.constructor" name="should default useDotNotation to true" time="0" />
44-
</testsuite>
45-
</testsuites>
28+
<?xml version="1.0" encoding="UTF-8"?>
29+
<testsuites>
30+
<testsuite name="JUnitXmlReporter" errors="0" tests="0" failures="0" time="0" timestamp="2013-05-24T10:23:58" />
31+
<testsuite name="JUnitXmlReporter.constructor" errors="0" skipped="1" tests="3" failures="1" time="0.006" timestamp="2013-05-24T10:23:58">
32+
<properties>
33+
<property name="java.vendor" value="Sun Microsystems Inc." />
34+
<property name="compiler.debug" value="on" />
35+
<property name="project.jdk.classpath" value="jdk.classpath.1.6" />
36+
</properties>
37+
<testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006">
38+
<failure message="test failure">Assertion failed</failure>
39+
</testcase>
40+
<testcase classname="JUnitXmlReporter.constructor" name="should default consolidate to true" time="0">
41+
<skipped />
42+
</testcase>
43+
<testcase classname="JUnitXmlReporter.constructor" name="should default useDotNotation to true" time="0" />
44+
</testsuite>
45+
</testsuites>
4646
`)
4747

4848
suites, err := junit.Ingest(xml)
4949
if err != nil {
50-
log.Fatalf("failed to ingest JUnit xml %v", err)
50+
log.Fatalf("failed to ingest JUnit xml %v", err)
5151
}
5252
```
5353

54+
You can then inspect the contents of the ingestes suites.
55+
56+
```go
57+
for _, suite := range suites {
58+
fmt.Println(suite.Name)
59+
for _, test := range suite.Tests {
60+
fmt.Printf(" %s\n", test.Name)
61+
if test.Error != nil {
62+
fmt.Printf(" %s: %s\n", test.Status, test.Error.Error())
63+
} else {
64+
fmt.Printf(" %s\n", test.Status)
65+
}
66+
}
67+
}
68+
```
69+
70+
And observe some output like this.
71+
72+
```
73+
JUnitXmlReporter
74+
JUnitXmlReporter.constructor
75+
should default path to an empty string
76+
failed: Assertion failed
77+
should default consolidate to true
78+
skipped
79+
should default useDotNotation to true
80+
passed
81+
```
82+
83+
### More Examples
84+
5485
Additionally, you can ingest an entire file.
5586

5687
```go
5788
suites, err := junit.IngestFile("test-reports/report.xml")
5889
if err != nil {
59-
log.Fatalf("failed to ingest JUnit xml %v", err)
90+
log.Fatalf("failed to ingest JUnit xml %v", err)
6091
}
6192
```
6293

6394
Or a list of multiple files.
6495

6596
```go
6697
suites, err := junit.IngestFiles([]string{
67-
"test-reports/report-1.xml",
68-
"test-reports/report-2.xml",
98+
"test-reports/report-1.xml",
99+
"test-reports/report-2.xml",
69100
})
70101
if err != nil {
71-
log.Fatalf("failed to ingest JUnit xml %v", err)
102+
log.Fatalf("failed to ingest JUnit xml %v", err)
72103
}
73104
```
74105

@@ -77,7 +108,7 @@ Or any `.xml` files inside of a directory.
77108
```go
78109
suites, err := junit.IngestDir("test-reports/")
79110
if err != nil {
80-
log.Fatalf("failed to ingest JUnit xml %v", err)
111+
log.Fatalf("failed to ingest JUnit xml %v", err)
81112
}
82113
```
83114

@@ -89,32 +120,32 @@ A single top level `testsuite` tag, containing multiple `testcase` instances.
89120

90121
```xml
91122
<testsuite>
92-
<testcase name="Test case 1" />
93-
<testcase name="Test case 2" />
123+
<testcase name="Test case 1" />
124+
<testcase name="Test case 2" />
94125
</testsuite>
95126
```
96127

97128
A single top level `testsuites` tag, containing multiple `testsuite` instances.
98129

99130
```xml
100131
<testsuites>
101-
<testsuite>
102-
<testcase name="Test case 1" />
103-
<testcase name="Test case 2" />
104-
</testsuite>
132+
<testsuite>
133+
<testcase name="Test case 1" />
134+
<testcase name="Test case 2" />
135+
</testsuite>
105136
</testsuites>
106137
```
107138

108139
(Despite not technically being valid XML) Multiple top level `testsuite` tags, containing multiple `testcase` instances.
109140

110141
```xml
111142
<testsuite>
112-
<testcase name="Test case 1" />
113-
<testcase name="Test case 2" />
143+
<testcase name="Test case 1" />
144+
<testcase name="Test case 2" />
114145
</testsuite>
115146
<testsuite>
116-
<testcase name="Test case 3" />
117-
<testcase name="Test case 4" />
147+
<testcase name="Test case 3" />
148+
<testcase name="Test case 4" />
118149
</testsuite>
119150
```
120151

0 commit comments

Comments
 (0)