Skip to content

fix(junit): count generated test cases - #457

Open
neallin917 wants to merge 2 commits into
cpplint:developfrom
neallin917:codex/fix-junit-test-counts
Open

fix(junit): count generated test cases#457
neallin917 wants to merge 2 commits into
cpplint:developfrom
neallin917:codex/fix-junit-test-counts

Conversation

@neallin917

@neallin917 neallin917 commented Jul 31, 2026

Copy link
Copy Markdown

Summary

  • count JUnit tests, failures, and errors from the generated test cases instead of individual lint findings
  • update unit and CLI sample expectations for grouped findings
  • document the corrected counts in the changelog

Root cause

FormatJUnitXML() groups all lint findings for a file into one <testcase> with one <failure>, but the suite attributes were calculated from the raw finding lists. JUnit consumers therefore saw many more tests and failures than the XML actually contained.

The suite counts now match the emitted structure: one error testcase when process errors exist, and one failed testcase per file containing lint findings.

Fixes #431

Validation

  • python -m pytest --no-cov cpplint_unittest.py -k testJUnitXML -vv
  • python -m pytest --no-cov 'cpplint_clitest.py::TestNoRepoSignature::test_samples[silly-junit]' -vv
  • python -m pytest — 231 passed, 96.46% coverage
  • python -m pylint cpplint.py
  • python -m mypy cpplint.py cpplint_clitest.py cpplint_unittest.py
  • pre-commit run --all-files
  • git diff --check

AI assistance disclosure

OpenAI Codex was used to investigate the issue, draft the implementation and regression updates, and run the validation commands listed above.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected JUnit XML reports so error counts indicate whether errors occurred.
    • Failure counts now reflect the number of affected files rather than individual failure messages.
    • Test counts now represent distinct generated test cases, preventing inflated totals when multiple messages belong to one case.
    • Updated sample reports and expectations to reflect accurate counts.
  • Documentation

    • Added a changelog entry describing the corrected JUnit failure-count reporting.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 52ded4f8-48e3-4f6d-9581-db90b6ce4c17

📥 Commits

Reviewing files that changed from the base of the PR and between c2a412b and b4371d2.

📒 Files selected for processing (3)
  • CHANGELOG.rst
  • cpplint.py
  • cpplint_unittest.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • CHANGELOG.rst
  • cpplint_unittest.py
  • cpplint.py

📝 Walkthrough

Walkthrough

JUnit XML reporting now counts failures by distinct filename. Unit test expectations, sample output, and the changelog reflect the corrected grouped testcase counts.

Changes

JUnit reporting

Layer / File(s) Summary
Correct JUnit count generation
cpplint.py
FormatJUnitXML counts failures by distinct filename while retaining the error-message count.
Update validation and sample output
cpplint_unittest.py, samples/silly-sample/junit.def, CHANGELOG.rst
The test expectation and sample report use two grouped testcases and failures. The changelog records the correction.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the JUnit change to count generated test cases.
Linked Issues check ✅ Passed The changes make JUnit tests and failures reflect testcase elements grouped by file, as required by issue #431.
Out of Scope Changes check ✅ Passed The code, tests, sample output, and changelog changes directly support the JUnit counting requirements in issue #431.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aaronliu0130 aaronliu0130 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer us grouping testcases by error category, but this is better than before so I'll approve this after a few minor changes.

Comment thread cpplint.py Outdated
Comment thread CHANGELOG.rst Outdated

@androvonx95 androvonx95 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked at b4371d2.

The narrowed change matches the review direction: failures is unique files with findings, changelog wording updated, and num_errors left as the raw error-message count. With only lint findings, tests/failures now match the emitted <testcase> count (e.g. 3 findings in 2 files → failures=2, tests=2, two testcases). Unit test testJUnitXML passes; full suite 206 passed.

LGTM.

@yangfan-yf-yf yangfan-yf-yf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at b4371d2.

This fixes #431's reported mismatch: lint findings are serialized as one failing testcase per file, and failures plus tests now use that same grouping. The unchanged process-error path is outside #431's lint-finding scope.

Verified locally:

python -m pytest -q --no-cov
231 passed

git diff --check b4371d2^..b4371d2
Passed

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JUnit support doesn't count amount of tests correctly

4 participants