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 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.Map.Entry;
26
27 import org.apache.maven.surefire.its.fixture.OutputValidator;
28 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
29 import org.apache.maven.surefire.its.fixture.SurefireLauncher;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameter;
34 import org.junit.runners.Parameterized.Parameters;
35
36 import static org.hamcrest.Matchers.containsString;
37 import static org.hamcrest.Matchers.equalTo;
38
39
40
41
42
43
44 @RunWith(Parameterized.class)
45 public class TestMethodPatternIT extends SurefireJUnit4IntegrationTestCase {
46 private static final String RUNNING_WITH_PROVIDER47 = "parallel='none', perCoreThreadCount=true, threadCount=0";
47
48 private static final String LEGACY_FORK_NODE = "org.apache.maven.plugin.surefire.extensions.LegacyForkNodeFactory";
49
50 private static final String SUREFIRE_FORK_NODE =
51 "org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory";
52
53 @Parameters
54 public static Iterable<Object[]> data() {
55 ArrayList<Object[]> args = new ArrayList<>();
56 args.add(new Object[] {"tcp"});
57 args.add(new Object[] {null});
58 return args;
59 }
60
61 @Parameter
62 @SuppressWarnings("checkstyle:visibilitymodifier")
63 public String profileId;
64
65 private OutputValidator runMethodPattern(String projectName, Map<String, String> props, String... goals)
66 throws Exception {
67 SurefireLauncher launcher = unpack(projectName, profileId == null ? "" : "-" + profileId);
68
69 if (profileId != null) {
70 launcher.activateProfile(profileId);
71 }
72
73 for (Entry<String, String> entry : props.entrySet()) {
74 launcher.sysProp(entry.getKey(), entry.getValue());
75 }
76 for (String goal : goals) {
77 launcher.addGoal(goal);
78 }
79 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
80 return launcher.showErrorStackTraces()
81 .debugLogging()
82 .executeTest()
83 .assertTestSuiteResults(2, 0, 0, 0)
84 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
85 }
86
87 @Test
88 public void testJUnit4() throws Exception {
89 runMethodPattern("junit4-method-pattern", Collections.emptyMap());
90 }
91
92 @Test
93 public void testJUnit4WithCategoryFilter() throws Exception {
94 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
95 SurefireLauncher launcher = unpack("junit4-method-pattern", profileId == null ? "" : "-" + profileId);
96
97 if (profileId != null) {
98 launcher.activateProfile(profileId);
99 }
100
101 launcher.debugLogging()
102 .addGoal("-Dgroups=junit4.SampleCategory")
103 .executeTest()
104 .assertTestSuiteResults(1, 0, 0, 0)
105 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
106 }
107
108 @Test
109 public void testTestNgMethodBefore() throws Exception {
110 Map<String, String> props = new HashMap<>();
111 props.put("testNgVersion", "6.14.3");
112 runMethodPattern("testng-method-pattern-before", props);
113 }
114
115 @Test
116 public void testTestNGMethodPattern() throws Exception {
117 Map<String, String> props = new HashMap<>();
118 props.put("testNgVersion", "6.14.3");
119 runMethodPattern("/testng-method-pattern", props);
120 }
121
122 @Test
123 public void testMethodPatternAfter() throws Exception {
124 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
125 SurefireLauncher launcher = unpack("testng-method-pattern-after", profileId == null ? "" : "-" + profileId);
126
127 if (profileId != null) {
128 launcher.activateProfile(profileId);
129 }
130
131 launcher.debugLogging()
132 .sysProp("testNgVersion", "6.14.3")
133 .executeTest()
134 .verifyErrorFree(2)
135 .verifyTextInLog("Called tearDown")
136 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
137 }
138 }