Skip to content

Commit cd9cbf2

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

18 files changed

+219
-2
lines changed

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/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,85 @@
1+
package test;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import org.testng.annotations.AfterClass;
6+
import org.testng.annotations.AfterMethod;
7+
import org.testng.annotations.AfterSuite;
8+
import org.testng.annotations.BeforeClass;
9+
import org.testng.annotations.BeforeMethod;
10+
import org.testng.annotations.BeforeSuite;
11+
import org.testng.annotations.Test;
12+
13+
public class ConfigurationMethodPrioritySampleTest {
14+
public static List<String> logs = new ArrayList<>();
15+
16+
@BeforeSuite(priority = 100)
17+
public void beforeSuiteA() {
18+
logs.add("beforeSuiteA");
19+
}
20+
21+
@BeforeSuite(priority = 1)
22+
public void beforeSuiteB() {
23+
logs.add("beforeSuiteB");
24+
}
25+
26+
@BeforeClass(priority = 100)
27+
public void beforeClassA() {
28+
logs.add("beforeClassA");
29+
}
30+
31+
@BeforeClass(priority = 1)
32+
public void beforeClassB() {
33+
logs.add("beforeClassB");
34+
}
35+
36+
@BeforeMethod(priority = 100)
37+
public void beforeMethodA() {
38+
logs.add("beforeMethodA");
39+
}
40+
41+
@BeforeMethod(priority = 1)
42+
public void beforeMethodB() {
43+
logs.add("beforeMethodB");
44+
}
45+
46+
@Test(priority = 100)
47+
public void testA() {
48+
logs.add("TestA");
49+
}
50+
51+
@Test(priority = 0)
52+
public void testB() {
53+
logs.add("TestB");
54+
}
55+
56+
@AfterSuite(priority = 100)
57+
public void afterSuiteA() {
58+
logs.add("afterSuiteA");
59+
}
60+
61+
@AfterSuite(priority = 1)
62+
public void afterSuiteB() {
63+
logs.add("afterSuiteB");
64+
}
65+
66+
@AfterClass(priority = 100)
67+
public void afterClassA() {
68+
logs.add("afterClassA");
69+
}
70+
71+
@AfterClass(priority = 1)
72+
public void afterClassB() {
73+
logs.add("afterClassB");
74+
}
75+
76+
@AfterMethod(priority = 100)
77+
public void afterMethodA() {
78+
logs.add("afterMethodA");
79+
}
80+
81+
@AfterMethod(priority = 1)
82+
public void afterMethodB() {
83+
logs.add("afterMethodB");
84+
}
85+
}

0 commit comments

Comments
 (0)