Skip to content

Junit tests failing during @BeforeClass methods have inaccurate xml report #3267

@olamy

Description

@olamy

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions