0

I have a Java project that uses Cucumber 7, Maven surefire, and JUnit 4. It is a project requirement to be able to rerun a failed feature file immediately after it fails (not rerun after the entire test run as done normally). So the flow would be something like:

  1. Run BeforeAll()
  2. Run Before()
  3. Run test
  4. If test fails, rerun until MAX_RETRY(2) is reached
  5. Run After()
  6. Do Steps 2-5 until all tests are run
  7. Run AfterAll()

I've seen people using Cucumber listeners for similar-ish problems but that is not an option for me as I'm on 7.3.3 and the EventListener is deprecated (AFAIK). Also read something about an extended Cucumber runner but is outdated. This is the closest response I found but uses Junit5. I've tried using the rerunFailingTestsCount parameter through Maven Surefire but that reruns the features after the entire test suite is run. If you have any other suggestions, I would be very grateful. Thanks!

This is my current Cucumber Runner (without rerun implemented). I run the main() to execute my tests.

@RunWith(Cucumber.class)
@CucumberOptions(
        tags="@xxx",
        plugin = {"pretty"},
        features = {"classpath:features"},
        glue = {"StepDefinitions"}
)

public class Runner {
    private static String[] options = {
            "classpath:Features",
            "--glue", "StepDefinitions",
            "--tags", "@xxx",
            "--plugin", "pretty",
    };

    public static void main(String[] args) {
            Stream<String> cucumberOptions = Stream.concat(Stream.of(defaultOptions), Stream.of(args));
            ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
            byte exitstatus = Main.run(cucumberOptions.toArray(String[]::new), contextClassLoader);

            // other stuff done for custom pdf reports
    }

}
  • It is not possible. Cucumber-JVM doesn't support retrying. – M.P. Korstanje Aug 03 '23 at 20:36
  • Sad. What about the solution that uses Junit5? Would it be possible to do it that way if I upgraded Junit? – user22334850 Aug 04 '23 at 12:37
  • Nope. That solution also executes cucumber twice. Generally speaking, I suspect nobody contributed this feature because it's pretty complicated. Detecting and retrying failed operations in the step however is pretty easy. Though personally I prefer to make the system under test stable so retrying isn't needed or make the tests wait for the appropriate condition if the action under test is asynchronous. – M.P. Korstanje Aug 04 '23 at 22:55

0 Answers0