Skip to content

JUnit reporter: emit only first failure per testcase#3081

Closed
Krishnayan-Bhatt wants to merge 2 commits intocatchorg:develfrom
Krishnayan-Bhatt:devel
Closed

JUnit reporter: emit only first failure per testcase#3081
Krishnayan-Bhatt wants to merge 2 commits intocatchorg:develfrom
Krishnayan-Bhatt:devel

Conversation

@Krishnayan-Bhatt
Copy link
Copy Markdown

Summary

The JUnit XML reporter previously emitted multiple <failure>, <error>, or <skipped> elements for a single <testcase> when several assertions failed (e.g. multiple CHECKs). Common JUnit consumers assume at most one such child per testcase, which breaks tools like junitparser with errors such as “Only one result allowed per test case.”

This change tracks whether a result element was already written for the current testcase section and suppresses further assertion result elements after the first.

Related issue

Fixes #1919

Testing

  • python tools/scripts/approvalTests.py <path-to-SelfTest> <temp-dir> — updated junit.sw / junit.sw.multi baselines
  • ctest -C Debug -R RunTests --test-dir <build-dir>

Aligns with common JUnit tooling expectations (e.g. junitparser) that
allow a single result element per testcase. Subsequent assertion failures
in the same testcase are omitted from the XML.

Fixes catchorg#1919

Made-with: Cursor
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (ccc49ba) to head (224a8c2).
⚠️ Report is 10 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #3081      +/-   ##
==========================================
+ Coverage   91.34%   91.35%   +0.02%     
==========================================
  Files         204      204              
  Lines        8899     8916      +17     
==========================================
+ Hits         8128     8145      +17     
  Misses        771      771              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

// events and write those out appropriately.
xml.writeAttribute( "status"_sr, "run"_sr );

bool resultElementEmitted = false;
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.

Why is this outside of writeAssertions?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You’re right — it doesn’t need to be here anymore. I’ll inline it in writeAssertions (and simplify the signature) in a follow-up commit.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done — I moved resultElementEmitted into writeAssertions so it’s only scoped to assertion output. Latest commit: 224a8c2.

Move resultElementEmitted into writeAssertions(); writeSection no longer
threads state that is only used while iterating assertions. Addresses review
feedback on the JUnit single-failure-per-testcase change.

Made-with: Cursor
@horenmar
Copy link
Copy Markdown
Member

horenmar commented Apr 4, 2026

You need either to

  1. get LLM that makes better changes
  2. guide it towards better output

As is, this doesn't pass the bar for useful contribution.

@horenmar horenmar closed this Apr 4, 2026
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 reporter allows multiple failures per test case

2 participants