Skip to content

Commit 0bd597d

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

22 files changed

+429
-3
lines changed

Diff for: 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)

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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
}

Diff for: 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

Diff for: 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;

Diff for: 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() {

Diff for: 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
}

Diff for: 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,68 @@
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+
8+
import org.testng.Assert;
9+
import org.testng.TestNG;
10+
import org.testng.annotations.Test;
11+
12+
import test.configuration.issue2663.ConfigurationMethodPrioritySampleTest;
13+
import test.configuration.issue2663.ConfigurationMethodPriorityWithGroupDependencySampleTest;
14+
15+
public class ConfigurationMethodPriorityTest extends SimpleBaseTest {
16+
17+
@Test(description = "GITHUB-2663")
18+
public void ensureThatPriorityWorksOnConfigurationMethods() {
19+
TestNG testng = create(ConfigurationMethodPrioritySampleTest.class);
20+
testng.run();
21+
assertThat(testng.getStatus()).isEqualTo(0);
22+
List<String> expectedLogs =
23+
Arrays.asList(
24+
"beforeSuiteB",
25+
"beforeSuiteA",
26+
"beforeClassB",
27+
"beforeClassA",
28+
"beforeMethodB",
29+
"beforeMethodA",
30+
"TestB",
31+
"afterMethodB",
32+
"afterMethodA",
33+
"beforeMethodB",
34+
"beforeMethodA",
35+
"TestA",
36+
"afterMethodB",
37+
"afterMethodA",
38+
"afterClassB",
39+
"afterClassA",
40+
"afterSuiteB",
41+
"afterSuiteA");
42+
assertThat(ConfigurationMethodPrioritySampleTest.logs).containsExactlyElementsOf(expectedLogs);
43+
}
44+
@Test
45+
public void ensureThatPriorityWorksOnConfigurationMethodsWithGroupDependency() {
46+
List<String> expectedOrder1 = Arrays.asList("s1", "s2", "s3","t1", "t2", "t3","c1", "c2", "c3","m1", "m2", "m3","test1","m1", "m2", "m3","test2","m1", "m2", "m3","test3");
47+
TestNG tng = create(ConfigurationMethodPriorityWithGroupDependencySampleTest.class);
48+
InvokedMethodNameListener listener = new InvokedMethodNameListener();
49+
tng.addListener(listener);
50+
tng.run();
51+
System.out.println(expectedOrder1);
52+
System.out.println(listener.getSucceedMethodNames());
53+
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
54+
}
55+
56+
@Test
57+
public void ensureThatPriorityWorksOnConfigurationMethodsWithMethodDependency() {
58+
List<String> expectedOrder1 = Arrays.asList("s1", "s2", "s3","t1", "t2", "t3","c1", "c2", "c3","m1", "m2", "m3","test1","m1", "m2", "m3","test2","m1", "m2", "m3","test3");
59+
TestNG tng = create(ConfigurationMethodPriorityWithGroupDependencySampleTest.class);
60+
InvokedMethodNameListener listener = new InvokedMethodNameListener();
61+
tng.addListener(listener);
62+
tng.run();
63+
System.out.println(expectedOrder1);
64+
System.out.println(listener.getSucceedMethodNames());
65+
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)