Skip to content

Conversation

@christianladam
Copy link
Contributor

Previously if you had deeply nested classes the BazelJUnitOutputListener would throw an exception. In JUnit5 TestExecutionListeners are not expected to throw exceptions and any exception just gets swallowed and logged as a warning. This would cause cases where an exception was thrown to output no test results and result in a successful test run even though there was a failure in the listener itself. The new logic attempts to get the closest parent segment that is a class type. This doesn't match the way things like gradle will output test XML but solves the problem with nested classes while keeping the output similar.

In terms of output this actually fixes an issue that is visible in the NestedClassesTest today, where the Second nested classes function result gets grouped into the outer class while the static First classes function result appears in a separate group as shown below:

NestedClassesTest
  shouldBeExecuted
  shouldBeExecuted
NestedClassesTest$First
  shouldBeExecuted

With the changes the grouping is fixed as shown below:

NestedClassesTest
  shouldBeExecuted
NestedClassesTest$First
  shouldBeExecuted
NestedClassesTest$Second
  shouldBeExecuted
NestedClassesTest$Second$Third
  shouldBeExecuted
NestedClassesTest$Second$Third$Fourth
  shouldBeExecuted
NestedClassesTest$Second$Third$Fourth$Fifth
  shouldBeExecuted

These groups appear unordered in UI like IntelliJ which isn't ideal, but these changes closely align with how things are done today, while avoiding just silently passing with no test output if you take this version of the NestedClassesTest and run it using the previous BazelJUnitOutputListener code.

@christianladam
Copy link
Contributor Author

This should resolve both #296 and #287.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@christianladam christianladam force-pushed the christianladam/fixDeeplyNestedClassesXml branch 2 times, most recently from 786369d to 9d26751 Compare July 24, 2025 16:30
@christianladam
Copy link
Contributor Author

christianladam commented Jul 24, 2025

Changes after approval include:

  1. running the format script to fix that error
  2. fixing the package name of the comparative NestedClassesTest
  3. regenerating the gradle/maven xml with the correct package and java 11.

There were no other changes beyond those.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

LGTM

@christianladam christianladam force-pushed the christianladam/fixDeeplyNestedClassesXml branch from 9d26751 to da244ba Compare July 24, 2025 17:43
@christianladam
Copy link
Contributor Author

Fixed the issue in the test output test where the children weren't being picked up because they weren't actually being added to the test plan. This is due to the original code always adding the groups but not necessarily adding tests. With the new code we only add the groups when there's actually a test.

Previously if you had deeply nested classes the BazelJUnitOutputListener
would throw an exception. In JUnit5 TestExecutionListeners are not expected
to throw exceptions and any exception just gets swallowed and logged as a
warning. This would cause cases where an exception was thrown to output no
test results and result in a successful test run even though there was a
failure in the listener itself. The new logic attempts to get the closest
parent segment that is a class type. This doesn't match the way things like
gradle will output test XML but solves the problem with nested classes while
keeping the output similar.

In terms of output this actually fixes an issue that is visible in the
NestedClassesTest today, where the Second nested classes function result
gets grouped into the outer class while the static First classes function
result appears in a separate group as shown below:

```
NestedClassesTest
  shouldBeExecuted
  shouldBeExecuted
NestedClassesTest$First
  shouldBeExecuted
```

With the changes the grouping is fixed as shown below:

```
NestedClassesTest
  shouldBeExecuted
NestedClassesTest$First
  shouldBeExecuted
NestedClassesTest$Second
  shouldBeExecuted
NestedClassesTest$Second$Third
  shouldBeExecuted
NestedClassesTest$Second$Third$Fourth
  shouldBeExecuted
NestedClassesTest$Second$Third$Fourth$Fifth
  shouldBeExecuted
```

These groups appear unordered in UI like IntelliJ which isn't ideal, but
these changes closely align with how things are done today, while avoiding
just silently passing with no test output if you take this version of the
NestedClassesTest and run it using the previous BazelJUnitOutputListener code.
@christianladam christianladam force-pushed the christianladam/fixDeeplyNestedClassesXml branch from da244ba to e906129 Compare July 24, 2025 17:53
@shs96c shs96c merged commit 201fa71 into bazel-contrib:main Jul 24, 2025
7 checks passed
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.

2 participants