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 testJUnit44() throws Exception {
89 runMethodPattern("junit44-method-pattern", Collections.emptyMap());
90 }
91
92 @Test
93 public void testJUnit48Provider4() throws Exception {
94 runMethodPattern("junit48-method-pattern", Collections.emptyMap(), "-P surefire-junit4");
95 }
96
97 @Test
98 public void testJUnit48Provider47() throws Exception {
99 runMethodPattern("junit48-method-pattern", Collections.emptyMap(), "-P surefire-junit47")
100 .verifyTextInLog(RUNNING_WITH_PROVIDER47);
101 }
102
103 @Test
104 public void testJUnit48WithCategoryFilter() throws Exception {
105 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
106 SurefireLauncher launcher = unpack("junit48-method-pattern", profileId == null ? "" : "-" + profileId);
107
108 if (profileId != null) {
109 launcher.activateProfile(profileId);
110 }
111
112 launcher.debugLogging()
113 .addGoal("-Dgroups=junit4.SampleCategory")
114 .executeTest()
115 .assertTestSuiteResults(1, 0, 0, 0)
116 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
117 }
118
119 @Test
120 public void testTestNgMethodBefore() throws Exception {
121 Map<String, String> props = new HashMap<>();
122 props.put("testNgVersion", "5.7");
123 props.put("testNgClassifier", "jdk15");
124 runMethodPattern("testng-method-pattern-before", props);
125 }
126
127 @Test
128 public void testTestNGMethodPattern() throws Exception {
129 Map<String, String> props = new HashMap<>();
130 props.put("testNgVersion", "5.7");
131 props.put("testNgClassifier", "jdk15");
132 runMethodPattern("/testng-method-pattern", props);
133 }
134
135 @Test
136 public void testMethodPatternAfter() throws Exception {
137 String cls = profileId == null ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE;
138 SurefireLauncher launcher = unpack("testng-method-pattern-after", profileId == null ? "" : "-" + profileId);
139
140 if (profileId != null) {
141 launcher.activateProfile(profileId);
142 }
143
144 launcher.debugLogging()
145 .sysProp("testNgVersion", "5.7")
146 .sysProp("testNgClassifier", "jdk15")
147 .executeTest()
148 .verifyErrorFree(2)
149 .verifyTextInLog("Called tearDown")
150 .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1));
151 }
152 }