├── README.md
└── examples
├── conventions.xml
├── junit-basic.xml
├── junit-complete.xml
├── testcase-output.xml
└── testcase-properties.xml
/README.md:
--------------------------------------------------------------------------------
1 | # Common JUnit XML Format & Examples
2 |
3 | _**Summary:** This project documents the common use of JUnit-style XML files by testing and CI tools, including full examples & common conventions. The goal of this project is to be the reference guide for JUnit-style XML files._
4 |
5 | The JUnit XML file format has been made popular by the JUnit project[^1] and has since become the de facto standard format to exchange test results between tools. JUnit-style XML files are generated by countless testing frameworks and are processed by CI tools, build servers and test management software to read and display test results.
6 |
7 | There is no official specification for the JUnit XML file format and various tools generate and support different flavors of this format. The goal of this project here is to document a common set of elements, attributes and conventions supported by many tools[^2]. If you are building software that produces or consumes JUnit-style XML files, this project might be a good starting point to learn about the format.
8 |
9 | 1. [Basic JUnit XML structure](#structure)
10 | 2. [Complete JUnit XML example](#example)
11 | 3. [Properties for suites & cases](#properties)
12 | 1. [Properties in test output](#properties-output)
13 | 4. [Attachments, screenshots and artifacts](#attachments)
14 | 1. [Attachment file properties](#attachments-files)
15 | 2. [Attachment URL properties](#attachments-urls)
16 | 3. [Attachment inline properties](#attachments-inline)
17 | 4. [Attachments in test output](#attachments-output)
18 | 5. [Common properties and conventions](#conventions)
19 | 1. [Attachments](#conventions-attachments)
20 | 2. [Steps](#conventions-steps)
21 | 3. [Type hints](#conventions-types)
22 | 6. [About this project](#about)
23 |
24 |
25 | ## Basic JUnit XML structure
26 |
27 | The following example shows the basic structure of a JUnit-style XML file. In this example we have two root test suites (think classes/folders), one sub test suite, and a couple of test cases (test results) in each suite.
28 |
29 | A test case is considered successful (passed) unless there is another result element underneath it. Most tools support the result elements `skipped`, `failure` and `error`.
30 |
31 | This basic example is not complete as it leaves out various attributes and additional elements supported by most tools. See the next section for a full example.
32 |
33 | Open example XML file (`junit-basic.xml`) →
34 |
35 | ```xml
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | ```
59 |
60 |
61 | ## Complete JUnit XML example
62 |
63 | The following example lists all commonly supported elements, attributes and typical values used by tools that generate or read JUnit-style XML files. Not all elements are supported by all tools, and not all tools follow and understand the same conventions.
64 |
65 | For example, [test cases properties](#properties) are not supported by all tools yet. Likewise, not all tools have options to [output attachments](#attachments). And different tools also expect or use different conventions for [names and values](#conventions).
66 |
67 | That said, if you are building tools that work with JUnit-style XML files, it can be a good idea to try to support most or all of these common elements and attributes.
68 |
69 | Open example XML file (`junit-complete.xml`) →
70 |
71 | ```xml
72 |
73 |
74 |
87 |
89 |
90 |
104 |
107 |
108 |
110 |
111 |
113 |
114 |
115 |
116 |
117 |
118 | Config line #1
119 | Config line #2
120 | Config line #3
121 |
122 |
123 |
124 |
126 | Data written to standard out.
127 |
128 |
130 | Data written to standard error.
131 |
132 |
142 |
144 |
146 |
148 |
149 |
150 |
152 |
154 |
155 |
156 |
157 |
158 |
160 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
171 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
182 |
183 | Data written to standard out.
184 |
185 |
186 | Data written to standard error.
187 |
188 |
189 |
190 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 | This text describes the purpose of this test case and provides
201 | an overview of what the test does and how it works.
202 |
203 |
204 |
205 |
206 |
207 | ```
208 |
209 |
210 | ## Properties for suites and cases
211 |
212 | Properties can be included for suites and cases to record additional information, such as version numbers, environment variables or links to CI pipelines. Properties are name / value pairs. Some tools support multi-line properties by including the property value as the element's text content.
213 |
214 | Open example XML file (`testcase-properties.xml`) →
215 | Open example XML file (`testcase-output.xml`) →
216 |
217 | ```xml
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 | Config line #1
226 | Config line #2
227 | Config line #3
228 |
229 |
230 |
231 |
232 |
233 | ```
234 |
235 | Originally, properties were only supported for test suite elements, not cases. However, many tools support properties for test cases now, including test frameworks such as [pytest](https://www.pytest.org/) and [Playwright](https://playwright.dev/), or test management tools such as [Testmo](https://www.testmo.com/) and many others. Often it can be useful to include additional details for test cases such as custom fields, test data or attachments.
236 |
237 | ```xml
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 | This text describes the purpose of this test case and provides
249 | an overview of what the test does and how it works.
250 |
251 |
252 |
253 |
254 |
255 | ```
256 |
257 | There can be multiple properties with the same name (e.g. multiple properties with the name `attachment`). Tools that read XML files should support this. However, many test frameworks have APIs that only support one property per name. In this case you should choose unique names for properties (e.g. `attachment1` and `attachment2`, [see below](#conventions)).
258 |
259 |
260 | ### Properties in test output
261 |
262 | Many test frameworks don't support properties for test cases yet. Another option to include properties in XML files is to add them to the test output (similar to referencing [attachments in the output](#attachments-output)). The advantage of this is that developers and testers can output properties even if their testing tool doesn't support test case properties.
263 |
264 | ```xml
265 |
266 |
267 | Output line #1
268 | Output line #2
269 |
270 | [[PROPERTY|author=Adrian]]
271 | [[PROPERTY|language=english]]
272 |
273 | [[PROPERTY|browser-log]]
274 | Log line #1
275 | Log line #2
276 | Log line #3
277 | [[/PROPERTY]]
278 |
279 |
280 | ```
281 |
282 | Each property is listed on its own line without any additional text. Each property consists of a name / value pair. Optionally, multi-line properties just specify the name without a value in the opening tag and end with a closing tag on its own line.
283 |
284 |
285 | ## Attachments, screenshots and artifacts
286 |
287 | Tests often generate or use additional files as part of a test run, such as log files, screenshots or build artifacts. Sometimes it can be useful to reference or include such files in the XML file. For example, for browser and UI tests it can be useful to include one or more screenshots to better understand why a test failed. Many testing tools support one or more of the following options for attachments.
288 |
289 |
290 | ### Attachment file properties
291 |
292 | The simplest way to reference files is to list local file paths as properties. This can be included for test suites and test cases. Different tools expect different property _names_ for attachments, but many tools simply expect the properties to be named `attachment` (or alternatively `attachment1` etc.).
293 |
294 | ```xml
295 |
296 |
297 |
298 |
299 |
300 |
301 | ```
302 |
303 |
304 | ### Attachment URL properties
305 |
306 | Files might also be uploaded to and stored with CI services or on build servers. For such scenarios it can be useful to reference files as URLs.
307 |
308 | ```xml
309 |
310 |
311 |
312 |
313 |
314 |
315 | ```
316 |
317 |
318 | ### Attachment inline properties
319 |
320 | For smaller files and to make it easier to record and transfer files together with an XML file, attachments can also be included inline as data URIs. Filenames can optionally be included with the non-standard `filename` attribute. Data should be encoded with base64.
321 |
322 | ```xml
323 |
324 |
325 |
326 |
327 |
328 |
329 | ```
330 |
331 |
332 | ### Attachments in test output
333 |
334 | Some tools support another way to reference files from the test output. This convention was first introduced by the [Jenkins JUnit Attachments](https://plugins.jenkins.io/junit-attachments/) plugin. This format is often used with tools that don't support test case properties. Each attachment is listed on a separate line (without any additional text) as part of the test's output (`system-out` or `system-err`) using the following format.
335 |
336 | ```xml
337 |
338 |
339 | Output line #1
340 | Output line #2
341 | [[ATTACHMENT|screenshots/dashboard.png]]
342 | [[ATTACHMENT|screenshots/users.png]]
343 |
344 |
345 | ```
346 |
347 |
348 | ## Common properties and conventions
349 |
350 | Test frameworks and testing tools can generally write and read properties with any name and value. There aren't any standards on how to name properties or how to format your values. However, various testing tools that read JUnit-style XML files expect certain property names and values. This section lists examples for commonly used property names and how tools format property values.
351 |
352 | Open example XML file (`conventions.xml`) →
353 |
354 |
355 | ### Attachments
356 |
357 | Name: `attachment*`
358 | Files attached to suites or cases, such as log files, screenshots, build artifacts or configurations.
359 |
360 | ```xml
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 | ```
369 |
370 |
371 | ### Steps
372 |
373 | Name: `step*`
374 | Steps can be useful to document the exact steps a test case performs. Tools can render
375 | all steps with optional statuses and sub fields.
376 |
377 | ```xml
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 | This is a more complex test step with multiple lines
389 | of text using a property with a text value.
390 |
391 |
392 |
394 |
395 |
396 |
397 |
398 |
399 |
401 |
403 | This line describes this step. You can also use HTML.
404 |
405 |
406 | You can optionally include more sub fields, e.g. for the expected results.
407 |
408 | ]]>
409 | ```
410 |
411 |
412 | ### Type hints
413 |
414 | Sometimes it can be useful to use more complex types for property values, such as HTML. Or tools support rendering specific property values in a special way. For example, URLs could be rendered as clickable links.
415 |
416 | To avoid tools having to guess the type of a property value by its content, some tools support _type hints_ for property values. Tools that generate JUnit-style XML files (e.g. test automation frameworks) do not need to provide special support for this, as type hints are just provided as part of property names, using the format `type:name`.
417 |
418 | There is no standard of types that tools support, so refer to your CI or test management tool's documentation to see if and which types might be supported. Here are some examples for types that tools might support:
419 |
420 | ```xml
421 |
424 |
425 |
426 |
427 |
428 |
429 |
430 | Log line #1
431 | Log line #2
432 | Log line #3
433 |
434 |
435 |
436 |
437 | TitleText
]]>
438 |
439 | ```
440 |
441 |
442 | ## About this project
443 |
444 | The goal of this project is to document the common use of JUnit-style XML files and describe how many tools implement support for this format. This project can be a starting point for builders of tools that generate or consume JUnit-style XML files. This file format has evolved over time and tools are adding support for test case properties and attachments as outlined in the above examples.
445 |
446 | The information in this project has been collected by the team at [Testmo](https://www.testmo.com/). Please submit an issue if you have questions or feedback or think some additional details should be added.
447 |
448 | [^1]: More precisely, the JUnit XML format was first introduced by the Ant build tool.
449 | [^2]: The format has evolved over time and new elements are used by tools now, so any original schema & XSD files are usually outdated.
450 |
--------------------------------------------------------------------------------
/examples/conventions.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | This text describes the purpose of this test case and provides
20 | an overview of what the test does and how it works.
21 |
22 |
23 |
26 |
27 |
28 | TitleText
]]>
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | This is a more complex test step with multiple lines
50 | of text using a property with a text value.
51 |
52 |
53 |
55 |
56 |
57 |
58 |
59 |
60 |
62 |
64 | This line describes this step. You can also use HTML.
65 |
66 |
67 | You can optionally include more sub fields, e.g. for the expected results.
68 |
69 | ]]>
70 |
71 |
72 |
76 | Title
91 | This is an HTML example.
92 | [[/PROPERTY]]
93 |
94 | [[ATTACHMENT|screenshots/dashboard.png]]
95 | [[ATTACHMENT|screenshots/users.png]]]]>
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/examples/junit-basic.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/examples/junit-complete.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
22 |
24 |
25 |
39 |
42 |
43 |
45 |
46 |
48 |
49 |
50 |
51 |
52 |
53 | Config line #1
54 | Config line #2
55 | Config line #3
56 |
57 |
58 |
59 |
61 | Data written to standard out.
62 |
63 |
65 | Data written to standard error.
66 |
67 |
77 |
79 |
81 |
83 |
84 |
85 |
87 |
89 |
90 |
91 |
92 |
93 |
95 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
106 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
117 |
118 | Data written to standard out.
119 |
120 |
121 | Data written to standard error.
122 |
123 |
124 |
125 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 | This text describes the purpose of this test case and provides
136 | an overview of what the test does and how it works.
137 |
138 |
139 |
140 |
141 |
142 |
--------------------------------------------------------------------------------
/examples/testcase-output.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | Config line #1
18 | Config line #2
19 | Config line #3
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | This text describes the purpose of this test case and provides
34 | an overview of what the test does and how it works.
35 |
36 |
37 |
38 |
41 |
42 | Output line #1
43 | Output line #2
44 |
45 | [[PROPERTY|author=Adrian]]
46 | [[PROPERTY|language=english]]
47 |
48 | [[PROPERTY|browser-log]]
49 | Log line #1
50 | Log line #2
51 | Log line #3
52 | [[/PROPERTY]]
53 |
54 | [[ATTACHMENT|screenshots/dashboard.png]]
55 | [[ATTACHMENT|screenshots/users.png]]
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/examples/testcase-properties.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | Config line #1
18 | Config line #2
19 | Config line #3
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | This text describes the purpose of this test case and provides
34 | an overview of what the test does and how it works.
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------