Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Junit formatter output #9780

Closed
jpserra opened this issue May 6, 2021 · 0 comments · Fixed by #9781
Closed

Better Junit formatter output #9780

jpserra opened this issue May 6, 2021 · 0 comments · Fixed by #9781

Comments

@jpserra
Copy link

jpserra commented May 6, 2021

Is your feature request related to a problem? Please describe.

When using junit formatter the output is:

<?xml version='1.0'?>
<testsuites>
  <testsuite name='rubocop'>
  ...
  </testsuite>
</testsuites>

which doesn't include some of the common attributes of junit (as per the documentation) such as:

    tests: The number of rules in the provider that were applied.
    failures: The number of rule violations in the provider.

Describe the solution you'd like

Provide a more informative output including the number of total tests ran and the number of failures in the testsuite element.

Describe alternatives you've considered

alternative 1

<?xml version='1.0'?>
<testsuites tests='175824' failures='0'>
  <testsuite name='rubocop'>
  ...
  </testsuite>
</testsuites>

alternative2

<?xml version='1.0'?>
<testsuite name='rubocop' tests='175824' failures='0'>
  ...
</testsuite>
koic added a commit to koic/rubocop that referenced this issue May 6, 2021
Fixes rubocop#9780.

This PR supports summary report for `JUnitFormatter`.

It adds the following attributes to the `<testsuite>` element.

- `tests` attribute ... Inspected file count.
- `failures` attribute ... Total offense count.

This is a JUnit format example:

```xml
% rubocop -f junit --display-only-failed lib/rubocop/formatter/junit_formatter.rb
<?xml version='1.0'?>
<testsuites>
  <testsuite name='rubocop' tests='1' failures='2'>
    <testcase classname='lib.rubocop.formatter.junit_formatter' name='Layout/LineLength'>
      <failure type='Layout/LineLength' message='Layout/LineLength: Line is too long. [110/100]'>
        /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/formatter/junit_formatter.rb:65:101
      </failure>
    </testcase>
    <testcase classname='lib.rubocop.formatter.junit_formatter' name='Metrics/AbcSize'>
      <failure type='Metrics/AbcSize' message='Metrics/AbcSize:
Assignment Branch Condition size for file_finished is too high. [&lt;8, 16, 2&gt; 18/17]'>
        /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/formatter/junit_formatter.rb:29:7
      </failure>
    </testcase>
  </testsuite>
</testsuites>
```

These mean the values of `1 file inspected` and `2 offenses detected` below.

```console
% rubocop lib/rubocop/formatter/junit_formatter.rb
Inspecting 1 file
(snip)

1 file inspected, 2 offenses detected, 2 offenses auto-correctable
```
bbatsov pushed a commit that referenced this issue May 7, 2021
Fixes #9780.

This PR supports summary report for `JUnitFormatter`.

It adds the following attributes to the `<testsuite>` element.

- `tests` attribute ... Inspected file count.
- `failures` attribute ... Total offense count.

This is a JUnit format example:

```xml
% rubocop -f junit --display-only-failed lib/rubocop/formatter/junit_formatter.rb
<?xml version='1.0'?>
<testsuites>
  <testsuite name='rubocop' tests='1' failures='2'>
    <testcase classname='lib.rubocop.formatter.junit_formatter' name='Layout/LineLength'>
      <failure type='Layout/LineLength' message='Layout/LineLength: Line is too long. [110/100]'>
        /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/formatter/junit_formatter.rb:65:101
      </failure>
    </testcase>
    <testcase classname='lib.rubocop.formatter.junit_formatter' name='Metrics/AbcSize'>
      <failure type='Metrics/AbcSize' message='Metrics/AbcSize:
Assignment Branch Condition size for file_finished is too high. [&lt;8, 16, 2&gt; 18/17]'>
        /Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/formatter/junit_formatter.rb:29:7
      </failure>
    </testcase>
  </testsuite>
</testsuites>
```

These mean the values of `1 file inspected` and `2 offenses detected` below.

```console
% rubocop lib/rubocop/formatter/junit_formatter.rb
Inspecting 1 file
(snip)

1 file inspected, 2 offenses detected, 2 offenses auto-correctable
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants