Junit formatter is not outputting according to XSD Schema
See original GitHub issueDescribe the bug
When using the JUnit formatter (--format=junit --output=test.xml
) then the output XML is not aligned with the XSD Schema (https://github.com/windyroad/JUnit-Schema/blob/master/JUnit.xsd).
JUnit only supports “error” or “failure”, not “warning”, “hint” etc.
To Reproduce
- Given an OpenAPI document that doesn’t have an
operationId
should create awarning
- Run this CLI command
lint myopapi.yaml --format=junit --output=test.xml
- See test.xml
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite package="org.spectral" time="0" tests="2" errors="2" name="openapi.yaml">
<testcase time="0" name="org.spectral.operation-description" classname="openapi">
<warning message="Operation `description` must be present and non-empty string."><![CDATA[line 13, col 9, Warning - Operation `description` must be present and non-empty string. (operation-description)]]></warning>
</testcase>
<testcase time="0" name="org.spectral.operation-operationId" classname="openapi">
<warning message="Operation should have an `operationId`."><![CDATA[line 13, col 9, Warning - Operation should have an `operationId`. (operation-operationId)]]></warning>
</testcase>
</testsuite>
</testsuites>
Expected behavior
- testsuites/testsuite/testcase/warning is not a valid element. must be either “error” or “failure”
- testsuites/testsuite@tests should not be equal “2” - ti should be the total number of tests run
- if all tests succeeds then a file should still be outputted (which should include the number of tests passed)
Additional context I would love to work on fixing this bug, but for now its here for reference 😉
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
java - How to validate an XML file against an XSD file?
The question is to validate an XML against a XSD. In this answer you are going further and getting a Parser object, which...
Read more >JUnit report is not showing my tests (#223132) - GitLab.org
Underlying issue seems to be that JUnit report files that are not well-formed xml or are not valid according to the "JUnit XML...
Read more >JUnit Format - Enterprise Tester - Catch Knowledge Base
This page documents the JUnit XML format itself. Basic Structure. Here is an example of a JUnit output file, showing a skip and...
Read more >Free Online XML Validator Against XSD Schema
This free online XML validator lets you validate your XML files against an XSD (XML Schema)
Read more >W3C XML Schema Definition Language (XSD) 1.1 Part 1
This document has been produced by the W3C XML Schema Working Group as ... does not suffice to make a document valid according...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we need to understand that there is a difference between formatting for console and JUnit/xUnit/mstest etc.
Humans look at console and that can show hints and other good recommendations. JUnit is usually read by machines aka. build systems which uses it to decide if it should fail or pass a build. So in this context hints doesn’t make sense as it wouldn’t know what to do with it 😃
In JUnit, if you pass the testsuites then it would “just” show “green” 123/123 tests passed. (That’s pretty much whats in the XML)
In case of a failure it would report “red” 122/123 tests passed and then the details of the error (incl. stacktrace, tracing etc. if present)
So what I’m trying to say is that what goes to the console vs. to a file doesn’t need to have the same information in it.
xUnit has the same construct in their schema: https://xunit.net/docs/format-xml-v2 => errors are documented - successes are only counted
That makes sense. That’s why I’m fine with going either way, I suppose testing systems either work and it’s a +1 or they fail and that’s a problem which has more details.
I think we should respect the fail severity and let folks decide if error or warning is what should be shown or trigger a failure, and the format itself can just trim out anything lower as they’re not relevant to the format.
– Phil Sturgeon @philsturgeon