Skip to content

Commit 645e2f6

Browse files
committed
Usage and format documentation
1 parent 92ca7b6 commit 645e2f6

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,115 @@ You can fetch this library by running the following
1515
go get -u github.com/joshdk/go-junit
1616
```
1717

18+
## Usage
19+
20+
### Data Ingestion
21+
22+
This library has a number of ingestion methods for convenient.
23+
24+
The simplest of which parses raw JUnit XML data.
25+
26+
```go
27+
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>
46+
`)
47+
48+
suites, err := junit.Ingest(xml)
49+
if err != nil {
50+
log.Fatalf("failed to ingest JUnit xml %v", err)
51+
}
52+
```
53+
54+
Additionally, you can ingest an entire file.
55+
56+
```go
57+
suites, err := junit.IngestFile("test-reports/report.xml")
58+
if err != nil {
59+
log.Fatalf("failed to ingest JUnit xml %v", err)
60+
}
61+
```
62+
63+
Or a list of multiple files.
64+
65+
```go
66+
suites, err := junit.IngestFiles([]string{
67+
"test-reports/report-1.xml",
68+
"test-reports/report-2.xml",
69+
})
70+
if err != nil {
71+
log.Fatalf("failed to ingest JUnit xml %v", err)
72+
}
73+
```
74+
75+
Or any `.xml` files inside of a directory.
76+
77+
```go
78+
suites, err := junit.IngestDir("test-reports/")
79+
if err != nil {
80+
log.Fatalf("failed to ingest JUnit xml %v", err)
81+
}
82+
```
83+
84+
### Data Formats
85+
86+
Due to the lack of implementation consistency in software that generates JUnit XML files, this library needs to take a somewhat looser approach to ingestion. As a consequence, many different possible JUnit formats can easily be ingested.
87+
88+
A single top level `testsuite` tag, containing multiple `testcase` instances.
89+
90+
```xml
91+
<testsuite>
92+
<testcase name="Test case 1" />
93+
<testcase name="Test case 2" />
94+
</testsuite>
95+
```
96+
97+
A single top level `testsuites` tag, containing multiple `testsuite` instances.
98+
99+
```xml
100+
<testsuites>
101+
<testsuite>
102+
<testcase name="Test case 1" />
103+
<testcase name="Test case 2" />
104+
</testsuite>
105+
</testsuites>
106+
```
107+
108+
(Despite not technically being valid XML) Multiple top level `testsuite` tags, containing multiple `testcase` instances.
109+
110+
```xml
111+
<testsuite>
112+
<testcase name="Test case 1" />
113+
<testcase name="Test case 2" />
114+
</testsuite>
115+
<testsuite>
116+
<testcase name="Test case 3" />
117+
<testcase name="Test case 4" />
118+
</testsuite>
119+
```
120+
121+
In all cases, omitting (or even duplicated) the XML declaration tag is allowed.
122+
123+
```xml
124+
<?xml version="1.0" encoding="UTF-8"?>
125+
```
126+
18127
## License
19128

20129
This library is distributed under the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE.txt](https://github.com/joshdk/go-junit/blob/master/LICENSE.txt) for more information.

0 commit comments

Comments
 (0)