Skip to content

[SUREFIRE-2148] Build fails if retried test classes failed during setupย #2749

Closed

Description

@jira-importer

Pavlo Shevchenko opened SUREFIRE-2148 and commented

Summary

If a JUnit5 test class fails during setup and succeeds on retry, then the surefire test goal and entire build will fail. On the other hand, if the failure occurs in a test method which succeeds on retry, then the goal and the build will succeed.

ย 

Reproducer

Test class with flaky setup:

package example;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FlakyClassTest {

    @BeforeAll
    public static void setup() throws IOException {
        String testSetupMarkerFile = "testSetupMarker.txt";
        if (!new File(testSetupMarkerFile).exists()) {
            System.out.println("I'm failing!");
            Files.write(Paths.get(testSetupMarkerFile), "Hello".getBytes());
            throw new RuntimeException("I'm failing!");
        } else {
            System.out.println("I'm passing!");
        }
    }

    @Test
    public void test() {
    }
} 

ย 

Test class with flaky method:

package example;

import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FlakyMethodTest {

    @Test
    public void test() throws IOException {
        String testMethodMarkerFile = "testMethodMarker.txt";
        if (!new File(testMethodMarkerFile).exists()) {
            System.out.println("I'm failing!");
            Files.write(Paths.get(testMethodMarkerFile), "Hello".getBytes());
            throw new RuntimeException("I'm failing!");
        } else {
            System.out.println("I'm passing!");
        }
    }
}

Surefire config:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.0.0-M8</version>
    <configuration>
        <rerunFailingTestsCount>1</rerunFailingTestsCount>
    </configuration>
</plugin>

ย 

Actual behavior

  1. This execution succeds:
mvn test -Dtest=*FlakyMethod*
  1. This execution fails:
mvn test -Dtest=*FlakyClass*

ย 

Expected behavior

  1. Both executions succeed

ย 

ย 

ย 


Affects: 3.0.0-M8

1 votes, 3 watchers

Activity

  1. jira-importer commented on Oct 10, 2024

    @jira-importer
    Author

    Pavlo Shevchenko commented

    Just stumbled over it again. It is a regression between 3.0.0-M4 and 3.0.0-M5. As of 3.5.1, it is still not working

  2. mauromol commented on Oct 9, 2025

    @mauromol

    I confirm this problem with Surefire Plugin 3.5.1. Is there any plan to address it?

  3. added this to the 3.6.0-M2 milestone on Aug 9, 2026
  4. added a commit that references this issue on Aug 9, 2026
    2f4ba64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority:majorMajor loss of function

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions