1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.surefire.its;
20  
21  import java.util.ArrayList;
22  
23  import org.apache.maven.shared.verifier.VerificationException;
24  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  import org.junit.runners.Parameterized;
29  import org.junit.runners.Parameterized.Parameter;
30  import org.junit.runners.Parameterized.Parameters;
31  
32  import static org.hamcrest.Matchers.containsString;
33  import static org.hamcrest.Matchers.equalTo;
34  
35  
36  
37  
38  
39  
40  
41  
42  @RunWith(Parameterized.class)
43  @SuppressWarnings("checkstyle:magicnumber")
44  public class JUnit47RerunFailingTestWithCucumberIT extends SurefireJUnit4IntegrationTestCase {
45      private static final String LEGACY_FORK_NODE = "org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory";
46  
47      private static final String SUREFIRE_FORK_NODE =
48              "org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory";
49  
50      @Parameters
51      public static Iterable<Object[]> data() {
52          ArrayList<Object[]> args = new ArrayList<>();
53          args.add(new Object[] {"tcp"});
54          args.add(new Object[] {null});
55          return args;
56      }
57  
58      @Parameter
59      @SuppressWarnings("checkstyle:visibilitymodifier")
60      public String profileId;
61  
62      private SurefireLauncher unpack() {
63          SurefireLauncher launcher =
64                  unpack("junit47-rerun-failing-tests-with-cucumber", profileId == null ? "" : "-" + profileId);
65  
66          if (profileId != null) {
67              launcher.activateProfile(profileId);
68          }
69  
70          return launcher;
71      }
72  
73      @Test
74      public void testRerunFailingErrorTestsFalse() throws VerificationException {
75          String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
76          unpack().debugLogging()
77                  .maven()
78                  .sysProp("surefire.rerunFailingTestsCount", 0)
79                  .withFailure()
80                  .executeTest()
81                  .assertTestSuiteResults(1, 0, 1, 0, 0)
82                  .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
83      }
84  
85      @Test
86      public void testRerunFailingErrorTestsWithOneRetry() throws VerificationException {
87          String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
88          unpack().debugLogging()
89                  .maven()
90                  .sysProp("surefire.rerunFailingTestsCount", 1)
91                  .withFailure()
92                  .executeTest()
93                  .assertTestSuiteResults(1, 0, 1, 0, 0)
94                  .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
95      }
96  
97      @Test
98      public void testRerunFailingErrorTestsTwoRetry() throws VerificationException {
99          String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
100         unpack().maven()
101                 .debugLogging()
102                 .sysProp("surefire.rerunFailingTestsCount", 2)
103                 .executeTest()
104                 .assertTestSuiteResults(1, 0, 0, 0, 2)
105                 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
106     }
107 }