|
8 | 8 | "fmt"
|
9 | 9 | "testing"
|
10 | 10 |
|
| 11 | + "github.com/stretchr/testify/assert" |
11 | 12 | "github.com/stretchr/testify/require"
|
12 | 13 | )
|
13 | 14 |
|
@@ -59,3 +60,114 @@ func TestIngest(t *testing.T) {
|
59 | 60 | })
|
60 | 61 | }
|
61 | 62 | }
|
| 63 | + |
| 64 | +func TestExamplesInTheWild(t *testing.T) { |
| 65 | + tests := []struct { |
| 66 | + title string |
| 67 | + filename string |
| 68 | + origin string |
| 69 | + check func(*testing.T, []Suite) |
| 70 | + }{ |
| 71 | + { |
| 72 | + title: "catchsoftware example", |
| 73 | + filename: "testdata/catchsoftware.xml", |
| 74 | + origin: "https://help.catchsoftware.com/display/ET/JUnit+Format", |
| 75 | + check: func(t *testing.T, suites []Suite) { |
| 76 | + assert.Len(t, suites, 2) |
| 77 | + assert.Len(t, suites[0].Tests, 0) |
| 78 | + assert.Len(t, suites[1].Tests, 3) |
| 79 | + assert.EqualError(t, suites[1].Tests[0].Error, "Assertion failed") |
| 80 | + }, |
| 81 | + }, |
| 82 | + { |
| 83 | + title: "cubic example", |
| 84 | + filename: "testdata/cubic.xml", |
| 85 | + origin: "https://llg.cubic.org/docs/junit/", |
| 86 | + check: func(t *testing.T, suites []Suite) { |
| 87 | + assert.Len(t, suites, 1) |
| 88 | + assert.Len(t, suites[0].Tests, 1) |
| 89 | + assert.Equal(t, "STDOUT text", suites[0].SystemOut) |
| 90 | + assert.Equal(t, "STDERR text", suites[0].SystemErr) |
| 91 | + assert.Equal(t, "STDOUT text", suites[0].Tests[0].SystemOut) |
| 92 | + assert.Equal(t, "STDERR text", suites[0].Tests[0].SystemErr) |
| 93 | + }, |
| 94 | + }, |
| 95 | + { |
| 96 | + title: "go-junit-report example", |
| 97 | + filename: "testdata/go-junit-report.xml", |
| 98 | + origin: "https://github.com/jstemmer/go-junit-report/blob/master/testdata/06-report.xml", |
| 99 | + check: func(t *testing.T, suites []Suite) { |
| 100 | + assert.Len(t, suites, 2) |
| 101 | + assert.Len(t, suites[0].Tests, 2) |
| 102 | + assert.Len(t, suites[1].Tests, 2) |
| 103 | + assert.Equal(t, "1.0", suites[0].Properties["go.version"]) |
| 104 | + assert.Equal(t, "1.0", suites[1].Properties["go.version"]) |
| 105 | + assert.EqualError(t, suites[1].Tests[0].Error, "file_test.go:11: Error message\nfile_test.go:11: Longer\n\terror\n\tmessage.") |
| 106 | + }, |
| 107 | + }, |
| 108 | + { |
| 109 | + title: "ibm example", |
| 110 | + filename: "testdata/ibm.xml", |
| 111 | + origin: "https://www.ibm.com/support/knowledgecenter/en/SSQ2R2_14.2.0/com.ibm.rsar.analysis.codereview.cobol.doc/topics/cac_useresults_junit.html", |
| 112 | + check: func(t *testing.T, suites []Suite) { |
| 113 | + assert.Len(t, suites, 1) |
| 114 | + assert.Len(t, suites[0].Tests, 1) |
| 115 | + assert.EqualError(t, suites[0].Tests[0].Error, "\nWARNING: Use a program name that matches the source file name\nCategory: COBOL Code Review – Naming Conventions\nFile: /project/PROGRAM.cbl\nLine: 2\n ") |
| 116 | + }, |
| 117 | + }, |
| 118 | + { |
| 119 | + title: "jenkinsci example", |
| 120 | + filename: "testdata/jenkinsci.xml", |
| 121 | + origin: "https://github.com/jenkinsci/junit-plugin/blob/master/src/test/resources/hudson/tasks/junit/junit-report-1463.xml", |
| 122 | + check: func(t *testing.T, suites []Suite) { |
| 123 | + assert.Len(t, suites, 1) |
| 124 | + assert.Len(t, suites[0].Tests, 6) |
| 125 | + assert.Equal(t, "\n", suites[0].Properties["line.separator"]) |
| 126 | + assert.Equal(t, `\`, suites[0].Properties["file.separator"]) |
| 127 | + }, |
| 128 | + }, |
| 129 | + { |
| 130 | + title: "nose2 example", |
| 131 | + filename: "testdata/nose2.xml", |
| 132 | + origin: "https://nose2.readthedocs.io/en/latest/plugins/junitxml.html", |
| 133 | + check: func(t *testing.T, suites []Suite) { |
| 134 | + assert.Len(t, suites, 1) |
| 135 | + assert.Len(t, suites[0].Tests, 25) |
| 136 | + assert.EqualError(t, suites[0].Tests[22].Error, "Traceback (most recent call last):\n File \"nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py\", line 13, in test_typeerr\n raise TypeError(\"oops\")\nTypeError: oops\n") |
| 137 | + }, |
| 138 | + }, |
| 139 | + { |
| 140 | + title: "python junit-xml example", |
| 141 | + filename: "testdata/python-junit-xml.xml", |
| 142 | + origin: "https://pypi.org/project/junit-xml/", |
| 143 | + check: func(t *testing.T, suites []Suite) { |
| 144 | + assert.Len(t, suites, 1) |
| 145 | + assert.Len(t, suites[0].Tests, 1) |
| 146 | + assert.Equal(t, "\n I am stdout!\n ", suites[0].Tests[0].SystemOut) |
| 147 | + assert.Equal(t, "\n I am stderr!\n ", suites[0].Tests[0].SystemErr) |
| 148 | + }, |
| 149 | + }, |
| 150 | + { |
| 151 | + title: "surefire example", |
| 152 | + filename: "testdata/surefire.xml", |
| 153 | + origin: "https://gist.github.com/rwbergstrom/6f0193b1a12dca9d358e6043ee6abba4", |
| 154 | + check: func(t *testing.T, suites []Suite) { |
| 155 | + assert.Len(t, suites, 1) |
| 156 | + assert.Len(t, suites[0].Tests, 1) |
| 157 | + assert.Equal(t, "\n", suites[0].Properties["line.separator"]) |
| 158 | + assert.Equal(t, "Hello, World\n", suites[0].Tests[0].SystemOut) |
| 159 | + assert.Equal(t, "I'm an error!\n", suites[0].Tests[0].SystemErr) |
| 160 | + }, |
| 161 | + }, |
| 162 | + } |
| 163 | + |
| 164 | + for index, test := range tests { |
| 165 | + name := fmt.Sprintf("#%d - %s", index+1, test.title) |
| 166 | + |
| 167 | + t.Run(name, func(t *testing.T) { |
| 168 | + suites, err := IngestFile(test.filename) |
| 169 | + require.NoError(t, err) |
| 170 | + test.check(t, suites) |
| 171 | + }) |
| 172 | + } |
| 173 | +} |
0 commit comments