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