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 reporter XML output missing required classname attribute on testcase element

See original GitHub issue

When producing JUnit XML output, the resulting XML file seems to be missing required attributes.

I found the following XML Schema Definition that indicates the required fields.

While I don’t think it is necessary to support every optional attribute, I think it would make sense to provide those that are mandatory.

I stumbled across this, as I tried to integrate ESlint output in GitLab CI, but GitLab CI will not display the report, as it requires the classname attribute to be present.

There is also an issue filed over at GitLab, but maybe it was more obvious to fix the issue in ESlint.

If you think here’s the right place to fix this, I’d be happy to contribute a Pull Request.

Tell us about your environment

  • ESLint Version: v5.8.0
  • Node Version: v10.12.0
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration: ø

Configuration
#  cat eslintconfig.json
{
  "plugins": [],
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module"
  },
  "extends": ["eslint:recommended"]
}
#  cat test.js
console.log('foo');

What did you expect to happen?

Expected the attribute classname to be present on element <testcase /> — I suggest that classname will be set to basename of the parents <testsuite/> file attribute.

<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="/path/to/test.js">
  <testcase time="0" classname="test" name="org.eslint.no-console">…</testcase>
</testsuite>
</testsuites>

What actually happened? Please include the actual, raw output from ESLint.

<!-- ⇒  ./node_modules/.bin/eslint -c eslintconfig.json -f junit test.js -->
<testsuites>
<testsuite package="org.eslint" time="0" tests="1" errors="1" name="/path/to/test.js">
  <testcase time="0" name="org.eslint.no-console">… </testcase>
</testsuite>
</testsuites>

Are you willing to submit a pull request to fix this bug?

👍

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
micheeecommented, Nov 15, 2018

@platinumazure Sorry, I did not want to rush things. The empty string turned out to be not too useful in terms of GitLab’s CI Panel (though valid w.r.t. to the schema).

I am locally playing around with using the filepath, but trimmed relative to the project root and without the filename suffix to have a things a little more readable for humans.

Currently it I imagine something like this:

<?xml version="1.0" encoding="utf-8"?>
<testsuites>
  <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Users/michael/Code/foo/foo-dev/src/frontend/controllers/PageController.js">
    <testcase time="0" name="org.eslint.no-console" classname="src/frontend/controllers/PageController">
      <failure message="Unexpected console statement."><![CDATA[line 41, col 9, Error - Unexpected console statement. (no-console)]]></failure>
    </testcase>
  </testsuite>
</testsuites>

Still this decision is kind of arbitrary as obviously the reporting format was invented for Java.

Feedback is very welcome. 😃

2reactions
cblesliecommented, Nov 15, 2018

mostly correct in the UI — multiple errors of the same category per File will only show up once —

@micheee, 90% of something, is better than 0% of nothing, hombré. I’ll take what I can get!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Summary Troubleshooting - CircleCI Support
Each test reporting tool may output their JUnit XML reports differently. This can cause some issues, in particular to our test-splitting feature ...
Read more >
java - how to configure the name and classname attributes on ...
I've tried running the karate-junit5 sample code and ran it using "mvn test". This is a sample of the generated JUnit XML report....
Read more >
PublishTestResults@2 - Publish Test Results v2 task
Required. Test results files. Default: **/TEST-*.xml. #searchFolder: '$(System.DefaultWorkingDirectory)' # string. Search folder ...
Read more >
Adding references to JUnit tests - my2cents
The idea is actually quite simple. Use custom annotations on test classes/methods to reference requirements and risks. Then have a custom JUnit ......
Read more >
Testsuite names are not displayed in JUnit Test Summaries
In a project with a lot of test classes, this leads to many testsuite elements. However, the JUnit Test Summaries in the MR...
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