Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

XUnit: invalid XML if running multiple suites #141

Open
givankin opened this issue Feb 11, 2015 · 4 comments
Open

XUnit: invalid XML if running multiple suites #141

givankin opened this issue Feb 11, 2015 · 4 comments

Comments

@givankin
Copy link

Hi,
the resulting XML for multiple suites is

<testsuite>...</testsuite>
<testsuite>...</testsuite>

Which is invalid XML (can't be parsed by Jenkins e.g.). According to XUnit Spec, it has to be:

<testsuites>
  <testsuite>...</testsuite>
  <testsuite>...</testsuite>
<testsuites>

From looking at code, I see the reason as this: as suites run one by one in a loop, reporter doesn't "know" anything about other suites and always acts as if there was a single suite - then the (valid) results for each suite are just concatenated.
I would be glad to submit a PR, but I even don't know where to start because from the point of view of the reporter it works as expected. In my Gruntfile I currently just use fs to wrap final XML it <testsuites>.

@shwangste
Copy link

+1

@kmiyashiro
Copy link
Owner

Is wrapping the output in <testsuites> actually what the XUnit spec declares? I don't use XUnit so I'm not sure if adding this wrapper will break whatever consumes the output for those that are running single suites.

@givankin
Copy link
Author

givankin commented Dec 7, 2015

I can't find any mention of a testuite in XUnit Specs now (v1: http://xunit.codeplex.com/wikipage?title=XmlFormat&referringTitle=Home, v2: https://xunit.github.io/docs/format-xml-v2.html). All I can say is that making this change manually fixes Jenkins reporter for me. So it looks like the problem is not that we don't conform with the XUnit here, but that we produce an invalid XML in case of multiple suites...

@givankin
Copy link
Author

givankin commented Dec 7, 2015

Just in case, if anybody is interested, here's what I use for Grunt:

  grunt.registerTask('fixXunitXml', function () {
    var fs = require('fs'),
      path = 'report/xunit.xml',
      xml = fs.readFileSync(path, 'utf8');
    xml = '<testsuites>' + xml + '</testsuites>';
    fs.writeFileSync(path, xml);
  });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants