You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "olamy (via GitHub)" <gi...@apache.org> on 2026/02/19 06:38:35 UTC

[I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

olamy opened a new issue, #3267:
URL: https://github.com/apache/maven-surefire/issues/3267

   ### Affected version
   
   3.5.4
   
   ### Bug description
   
   Given the following class:
   ```
   
   package test;
   
   
   import org.junit.jupiter.api.BeforeAll;
   import org.junit.jupiter.api.Test;
   
   import static org.junit.jupiter.api.Assertions.fail;
   
   public class SomeTest {
       @BeforeAll
       public static void setUpClass() {
           double r = Math.random();
           if (r < 0.3) {
               fail();
           }
       }
   
       @Test
       public void test1() {
       }
   }
   
   
   ```
   
   It's failing randomly.
   
   When success the file `target/surefire-reports/TEST-test.SomeTest.xml` contains the correct method name
   ```
   <testcase name="test1" classname="test.SomeTest" time="0.01"/>
   ```
   When failing there is no method name
   ```
     <testcase name="" classname="test.SomeTest" time="0.043">
       <failure type="org.opentest4j.AssertionFailedError&#10;	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java"><![CDATA[org.opentest4j.AssertionFailedError
   	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:34)
   	at org.junit.jupiter.api.Assertions.fail(Assertions.java:116)
   	at test.SomeTest.setUpClass(SomeTest.java:38)
   	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
   	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
   	stack trace simplified
   ]]></failure>
     </testcase>
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

Posted by "MilanTyagi2004 (via GitHub)" <gi...@apache.org>.
MilanTyagi2004 commented on issue #3267:
URL: https://github.com/apache/maven-surefire/issues/3267#issuecomment-4073350755

   Hi Olamy,
   
   I looked into this issue and was able to reproduce the behavior. The root cause seems to be tied to the JUnit lifecycle - when `@BeforeAll` fails, no test methods are executed, so Surefire ends up creating a `<testcase>` entry without a method name.
   
   A possible approach to fix this would be:
   
   * Detect failures occurring in lifecycle methods like `@BeforeAll`
   * Instead of emitting a `<testcase>` with an empty name, map this failure to a synthetic or meaningful identifier (e.g., `"classInitialization"` or `"@BeforeAll"`)
   * Alternatively, associate the failure with all discovered test methods so reports remain consistent and tools consuming the XML don’t break
   
   This way, the report would always contain a valid test case name and be more reliable for CI and reporting tools.
   
   If this approach sounds reasonable, I’d be happy to work on implementing the fix.
   
   Would it be okay to assign this issue to me?
   
   Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy commented on issue #3267:
URL: https://github.com/apache/maven-surefire/issues/3267#issuecomment-4073769825

   @MilanTyagi2004 sure feel free to have a look and propose a PR


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

Posted by "MilanTyagi2004 (via GitHub)" <gi...@apache.org>.
MilanTyagi2004 commented on issue #3267:
URL: https://github.com/apache/maven-surefire/issues/3267#issuecomment-4091166705

   Hi @olamy,
   
   I’ve submitted a PR to address this issue (#3267).
   
   It fixes:
   - empty <testcase name=""> for FAILED @BeforeAll/@AfterAll
   - missing <testcase> entries for ABORTED cases
   
   Would appreciate your review when you have time.
   
   Thanks!
   
   Pr  - #3329 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

Posted by "olamy (via GitHub)" <gi...@apache.org>.
olamy closed issue #3267: Junit tests failing during @BeforeClass methods have inaccurate xml report
URL: https://github.com/apache/maven-surefire/issues/3267


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Junit tests failing during @BeforeClass methods have inaccurate xml report [maven-surefire]

Posted by "MilanTyagi2004 (via GitHub)" <gi...@apache.org>.
MilanTyagi2004 commented on issue #3267:
URL: https://github.com/apache/maven-surefire/issues/3267#issuecomment-4109168696

   Hi @olamy 
   i've implement the IT for the issue , as you told.
   
   would appreciate your review when you have time.
   Thanks
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org