- 
                Notifications
    You must be signed in to change notification settings 
- Fork 79
fix: support nested classes properly #351
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
fix: support nested classes properly #351
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you!
786369d    to
    9d26751      
    Compare
  
    | Changes after approval include: 
 There were no other changes beyond those. | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
9d26751    to
    da244ba      
    Compare
  
    | 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.
da244ba    to
    e906129      
    Compare
  
    
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:
With the changes the grouping is fixed as shown below:
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.