- 
                Notifications
    You must be signed in to change notification settings 
- Fork 79
Add support for @AfterAll in XML report #300
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
Conversation
        
          
                java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListener.java
          
            Show resolved
            Hide resolved
        
              
          
                java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListener.java
          
            Show resolved
            Hide resolved
        
              
          
                java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/TestData.java
          
            Show resolved
            Hide resolved
        
      28684ad    to
    f71f699      
    Compare
  
    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.
For completeness, we should also modify the comparative test cases to try and capture how this will work with (eg) a parameterised test. However, this is already better than what we have, so if you kindly rework the test in BazelJUnitOuputListenerTest to be more like the others in that class, I'll happily merge this!
        
          
                java/src/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListener.java
          
            Show resolved
            Hide resolved
        
              
          
                java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java
          
            Show resolved
            Hide resolved
        
              
          
                java/test/com/github/bazel_contrib/contrib_rules_jvm/junit5/BazelJUnitOutputListenerTest.java
          
            Show resolved
            Hide resolved
        
      | @shs96c I'm not sure what tests to add to mimic the other ones that will provide value. Nothing about the creation of the TestData results are incorrect itself and the method itself is private. I can make  Feel free to chat to me on Slack about this as well. | 
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.
OK. Let's land this, and if we find issues we can always iterate. Thank you for your patience with the review!
Could you please rebase, and I'll merge this in?
Writing a simple test like
```
package com.library;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
public class AlwaysFailTest {
    @test
    public void doNothingTest() {
        System.out.println("Hi there!");
    }
    @afterall
    public static void alwaysFail() {
        throw new RuntimeException("Always failing.");
    }
}
```
Produces an XML that seems to look like it succeeds.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="com.library.AlwaysFailTest" timestamp="2024-10-10T21:19:11.522176Z" hostname="KHK9NLVQGN" tests="2" failures="0" errors="0" disabled="0" skipped="0" package="">
    <properties/>
    <testcase name="doNothingTest" classname="com.library.AlwaysFailTest" time="0.03">
      <system-out><![CDATA[Hi there!
]]></system-out>
    </testcase>
  </testsuite>
</testsuites>
```
Bazel itself correctly identifies it fails. The Junit4 reporter also included with Bazel natively correclty reports the failure in the XML output.
Augment the Junit listener to add support for static methods and add them to the JUnit output.
Doing so produces the following XML.
```xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
  <testsuite name="com.library.AlwaysFailTest" timestamp="2024-10-10T21:49:02.096648Z" hostname="KHK9NLVQGN" tests="3" failures="1" errors="0" disabled="0" skipped="0" package="">
    <properties/>
    <testcase name="com.library.AlwaysFailTest" classname="com.library.AlwaysFailTest" time="0.05">
      <failure message="Always failing." type="java.lang.RuntimeException"><![CDATA[java.lang.RuntimeException: Always failing.
	at com.library.AlwaysFailTest.alwaysFail(AlwaysFailTest.java:20)
...
	at com.github.bazel_contrib.contrib_rules_jvm.junit5.JUnit5Runner.main(JUnit5Runner.java:39)
]]></failure>
    </testcase>
    <testcase name="doNothingTest" classname="com.library.AlwaysFailTest" time="0.03">
      <system-out><![CDATA[Hi there!
]]></system-out>
    </testcase>
  </testsuite>
</testsuites>
```
    f71f699    to
    5c9f014      
    Compare
  
    | @shs96c rebased; | 
| I'm not sure about the 1 failure; there are no logs. | 
| Raw logs look like it timed out downloading  | 
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.
This change started logging testsuite also as test case. Now incorrectly logs the number of tests to number of tests + number of test classes.
| @amishra-u Can you give an example? | 
…res (#328) fixes: #327 1. Updated code to propagate the test suite failure to each test case. 2. The test suite failure will be propagated to each child node, even if the test is not executed. 3. Additionally, this change fixes the bug introduced in #300, which incorrectly logged the test_suite as a testcase and logged incorrect values for the "tests" attribute in the <testsuite> node.
Writing a simple test like
Produces an XML that seems to look like it succeeds.
Bazel itself correctly identifies it fails. The Junit4 reporter also included with Bazel natively correclty reports the failure in the XML output.
Augment the Junit listener to add support for static methods and add them to the JUnit output.
Doing so produces the following XML.
Co-authored-by: Vince Rose [email protected]