Skip to content

Commit d4be735

Browse files
author
Martin Aldrin
committed
Add support for Priority in Configuration Methods
1 parent 49dbdc9 commit d4be735

23 files changed

+479
-11
lines changed

CHANGES.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Current
2-
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals.
2+
New: GITHUB-2663 Add support for Priority in Configuration Methods. (Martin Aldrin)
3+
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals. (Martin Aldrin)
34
Fixed: GITHUB-2229: Restore @BeforeGroups and @AfterGroups Annotations functionality (Krishnan Mahadevan)
45
Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan)
56
Fixed: GITHUB-2535: TestResult.getEndMillis() returns 0 for skipped configuration - after upgrading testng to 7.0 + (Krishnan Mahadevan)

testng-core-api/src/main/java/org/testng/annotations/AfterClass.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the value (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/AfterGroups.java

+7
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@
8787
* @return the value (default 0)
8888
*/
8989
long timeOut() default 0;
90+
91+
/**
92+
* The scheduling priority. Lower priorities will be scheduled first.
93+
*
94+
* @return the value (default 0)
95+
*/
96+
int priority() default 0;
9097
}

testng-core-api/src/main/java/org/testng/annotations/AfterMethod.java

+7
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,11 @@
9999
* @return the value (default 0)
100100
*/
101101
long timeOut() default 0;
102+
103+
/**
104+
* The scheduling priority. Lower priorities will be scheduled first.
105+
*
106+
* @return the value (default 0)
107+
*/
108+
int priority() default 0;
102109
}

testng-core-api/src/main/java/org/testng/annotations/AfterSuite.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the valude (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/AfterTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the value (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/BeforeClass.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the value (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/BeforeGroups.java

+7
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@
8787
* @return the value (default 0)
8888
*/
8989
long timeOut() default 0;
90+
91+
/**
92+
* The scheduling priority. Lower priorities will be scheduled first.
93+
*
94+
* @return the value (default 0)
95+
*/
96+
int priority() default 0;
9097
}

testng-core-api/src/main/java/org/testng/annotations/BeforeMethod.java

+7
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,11 @@
9999
* @return the value (default 0)
100100
*/
101101
long timeOut() default 0;
102+
103+
/**
104+
* The scheduling priority. Lower priorities will be scheduled first.
105+
*
106+
* @return the value (default 0)
107+
*/
108+
int priority() default 0;
102109
}

testng-core-api/src/main/java/org/testng/annotations/BeforeSuite.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the value (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/BeforeTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@
7777
* @return the value (default 0)
7878
*/
7979
long timeOut() default 0;
80+
81+
/**
82+
* The scheduling priority. Lower priorities will be scheduled first.
83+
*
84+
* @return the value (default 0)
85+
*/
86+
int priority() default 0;
8087
}

testng-core-api/src/main/java/org/testng/annotations/ITestOrConfiguration.java

+7
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,11 @@ public interface ITestOrConfiguration extends IParameterizable {
4040
String getDescription();
4141

4242
void setDescription(String description);
43+
44+
/**
45+
* The scheduling priority. Lower priorities will be scheduled first.
46+
*
47+
* @return the value (default 0)
48+
*/
49+
int getPriority();
4350
}

testng-core/src/main/java/org/testng/internal/ClonedMethod.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public int getPriority() {
327327

328328
@Override
329329
public void setPriority(int priority) {
330-
// ignored
330+
m_method.setPriority(priority);
331331
}
332332

333333
@Override
@@ -337,7 +337,7 @@ public int getInterceptedPriority() {
337337

338338
@Override
339339
public void setInterceptedPriority(int priority) {
340-
// ignored
340+
m_method.setInterceptedPriority(priority);
341341
}
342342

343343
@Override

testng-core/src/main/java/org/testng/internal/ConfigurationMethod.java

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ private void init() {
409409
m_inheritGroupsFromTestClass = annotation.getInheritGroups();
410410
setEnabled(annotation.getEnabled());
411411
setDescription(annotation.getDescription());
412+
setPriority(annotation.getPriority());
412413
}
413414

414415
if (annotation != null && annotation.isFakeConfiguration()) {
@@ -503,6 +504,7 @@ public ConfigurationMethod clone() {
503504
clone.setDescription(getDescription());
504505
clone.setEnabled(getEnabled());
505506
clone.setParameterInvocationCount(getParameterInvocationCount());
507+
clone.setPriority(getPriority());
506508
clone.m_inheritGroupsFromTestClass = inheritGroupsFromTestClass();
507509

508510
return clone;

testng-core/src/main/java/org/testng/internal/MethodHelper.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,17 @@ private static Graph<ITestNGMethod> topologicalSort(
289289
}
290290
predecessors.addAll(Arrays.asList(methodsNamed));
291291
}
292-
if (XmlTest.isGroupBasedExecution(xmlTest)) {
293-
String[] groupsDependedUpon = m.getGroupsDependedUpon();
294-
if (groupsDependedUpon.length > 0) {
295-
for (String group : groupsDependedUpon) {
296-
ITestNGMethod[] methodsThatBelongToGroup =
297-
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
298-
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
299-
}
292+
// Should not be part of this commit. just added until GITHUB-2664 is solved.
293+
// if (XmlTest.isGroupBasedExecution(xmlTest)) {
294+
String[] groupsDependedUpon = m.getGroupsDependedUpon();
295+
if (groupsDependedUpon.length > 0) {
296+
for (String group : groupsDependedUpon) {
297+
ITestNGMethod[] methodsThatBelongToGroup =
298+
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
299+
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
300300
}
301301
}
302+
// }
302303

303304
for (ITestNGMethod predecessor : predecessors) {
304305
result.addPredecessor(m, predecessor);

testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ private static void finishInitialize(
197197
result.setGroups(bs.getGroups());
198198
result.setInheritGroups(bs.getInheritGroups());
199199
result.setTimeOut(bs.getTimeOut());
200+
result.setPriority(bs.getPriority());
200201
}
201202

202203
public static List<Class<? extends IAnnotation>> getAllAnnotations() {

testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
109109
false,
110110
false,
111111
bs.timeOut(),
112+
bs.priority(),
112113
new String[0]);
113114
} else if (annotationClass == IAfterSuite.class) {
114115
AfterSuite bs = (AfterSuite) a;
@@ -136,6 +137,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
136137
false,
137138
false,
138139
bs.timeOut(),
140+
bs.priority(),
139141
new String[0]);
140142
} else if (annotationClass == IBeforeTest.class) {
141143
BeforeTest bs = (BeforeTest) a;
@@ -163,6 +165,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
163165
false,
164166
false,
165167
bs.timeOut(),
168+
bs.priority(),
166169
new String[0]);
167170
} else if (annotationClass == IAfterTest.class) {
168171
AfterTest bs = (AfterTest) a;
@@ -190,6 +193,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
190193
false,
191194
false,
192195
bs.timeOut(),
196+
bs.priority(),
193197
new String[0]);
194198
} else if (annotationClass == IBeforeGroups.class) {
195199
BeforeGroups bs = (BeforeGroups) a;
@@ -218,6 +222,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
218222
false,
219223
false,
220224
bs.timeOut(),
225+
bs.priority(),
221226
new String[0]);
222227
} else if (annotationClass == IAfterGroups.class) {
223228
AfterGroups bs = (AfterGroups) a;
@@ -246,6 +251,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
246251
false,
247252
false,
248253
bs.timeOut(),
254+
bs.priority(),
249255
new String[0]);
250256
} else if (annotationClass == IBeforeClass.class) {
251257
BeforeClass bs = (BeforeClass) a;
@@ -273,6 +279,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
273279
false,
274280
false,
275281
bs.timeOut(),
282+
bs.priority(),
276283
new String[0]);
277284
} else if (annotationClass == IAfterClass.class) {
278285
AfterClass bs = (AfterClass) a;
@@ -300,6 +307,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
300307
false,
301308
false,
302309
bs.timeOut(),
310+
bs.priority(),
303311
new String[0]);
304312
} else if (annotationClass == IBeforeMethod.class) {
305313
BeforeMethod bs = (BeforeMethod) a;
@@ -327,6 +335,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
327335
bs.firstTimeOnly(),
328336
false,
329337
bs.timeOut(),
338+
bs.priority(),
330339
bs.onlyForGroups());
331340
} else if (annotationClass == IAfterMethod.class) {
332341
AfterMethod bs = (AfterMethod) a;
@@ -354,6 +363,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
354363
false,
355364
bs.lastTimeOnly(),
356365
bs.timeOut(),
366+
bs.priority(),
357367
bs.onlyForGroups());
358368
}
359369

@@ -383,6 +393,7 @@ private IAnnotation createConfigurationTag(
383393
boolean firstTimeOnly,
384394
boolean lastTimeOnly,
385395
long timeOut,
396+
int priority,
386397
String[] groupFilters) {
387398
ConfigurationAnnotation result = new ConfigurationAnnotation();
388399
result.setIsBeforeGroups(isBeforeGroups);
@@ -410,6 +421,7 @@ private IAnnotation createConfigurationTag(
410421
result.setFirstTimeOnly(firstTimeOnly);
411422
result.setLastTimeOnly(lastTimeOnly);
412423
result.setTimeOut(timeOut);
424+
result.setPriority(priority);
413425

414426
return result;
415427
}

testng-core/src/main/java/org/testng/internal/annotations/TestOrConfiguration.java

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void setDescription(String description) {
6262
m_description = description;
6363
}
6464

65+
@Override
6566
public int getPriority() {
6667
return m_priority;
6768
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package test;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.Arrays;
6+
import java.util.List;
7+
import org.testng.Assert;
8+
import org.testng.TestNG;
9+
import org.testng.annotations.Test;
10+
import test.configuration.issue2663.ConfigurationMethodPrioritySampleTest;
11+
import test.configuration.issue2663.ConfigurationMethodPriorityWithGroupDependencySampleTest;
12+
import test.configuration.issue2663.ConfigurationMethodPriorityWithMethodDependencySampleTest;
13+
14+
public class ConfigurationMethodPriorityTest extends SimpleBaseTest {
15+
16+
@Test(description = "GITHUB-2663")
17+
public void ensureThatPriorityWorksOnConfigurationMethods() {
18+
TestNG testng = create(ConfigurationMethodPrioritySampleTest.class);
19+
testng.run();
20+
assertThat(testng.getStatus()).isEqualTo(0);
21+
List<String> expectedLogs =
22+
Arrays.asList(
23+
"beforeSuiteB",
24+
"beforeSuiteA",
25+
"beforeClassB",
26+
"beforeClassA",
27+
"beforeMethodB",
28+
"beforeMethodA",
29+
"TestB",
30+
"afterMethodB",
31+
"afterMethodA",
32+
"beforeMethodB",
33+
"beforeMethodA",
34+
"TestA",
35+
"afterMethodB",
36+
"afterMethodA",
37+
"afterClassB",
38+
"afterClassA",
39+
"afterSuiteB",
40+
"afterSuiteA");
41+
assertThat(ConfigurationMethodPrioritySampleTest.logs).containsExactlyElementsOf(expectedLogs);
42+
}
43+
44+
@Test(description = "GITHUB-2663")
45+
public void ensureThatPriorityWorksOnConfigurationMethodsWithGroupDependency() {
46+
List<String> expectedOrder1 =
47+
Arrays.asList(
48+
"s3", "s2", "s1", "t3", "t2", "t1", "c3", "c2", "c1", "m3", "m2", "m1", "test3", "m3",
49+
"m2", "m1", "test2", "m3", "m2", "m1", "test1");
50+
TestNG tng = create(ConfigurationMethodPriorityWithGroupDependencySampleTest.class);
51+
InvokedMethodNameListener listener = new InvokedMethodNameListener();
52+
tng.addListener(listener);
53+
tng.run();
54+
System.out.println(expectedOrder1);
55+
System.out.println(listener.getSucceedMethodNames());
56+
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
57+
}
58+
59+
@Test(description = "GITHUB-2663")
60+
public void ensureThatPriorityWorksOnConfigurationMethodsWithMethodDependency() {
61+
List<String> expectedOrder1 =
62+
Arrays.asList(
63+
"s3", "s2", "s1", "t3", "t2", "t1", "c3", "c2", "c1", "m3", "m2", "m1", "test3", "m3",
64+
"m2", "m1", "test2", "m3", "m2", "m1", "test1");
65+
TestNG tng = create(ConfigurationMethodPriorityWithMethodDependencySampleTest.class);
66+
InvokedMethodNameListener listener = new InvokedMethodNameListener();
67+
tng.addListener(listener);
68+
tng.run();
69+
System.out.println(expectedOrder1);
70+
System.out.println(listener.getSucceedMethodNames());
71+
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
72+
}
73+
}

0 commit comments

Comments
 (0)