question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Junit formatter is not outputting according to XSD Schema

See original GitHub issue

Describe 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

  1. Given an OpenAPI document that doesn’t have an operationId should create a warning
  2. Run this CLI command lint myopapi.yaml --format=junit --output=test.xml
  3. 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CasperJcommented, Sep 30, 2019

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

0reactions
philsturgeoncommented, Sep 30, 2019

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

On Sep 30, 2019, at 21:17, CasperJ notifications@github.com wrote:

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 would 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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found