Skip to content

Commit

Permalink
Add support for Priority in Configuration Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Aldrin committed Oct 27, 2021
1 parent 49dbdc9 commit d4be735
Show file tree
Hide file tree
Showing 23 changed files with 479 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
@@ -1,5 +1,6 @@
Current
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals.
New: GITHUB-2663 Add support for Priority in Configuration Methods. (Martin Aldrin)
Fixed: GITHUB-2653: Assert methods requires casting since TestNg 7.0 for mixed boxed and unboxed primitives in assertEquals. (Martin Aldrin)
Fixed: GITHUB-2229: Restore @BeforeGroups and @AfterGroups Annotations functionality (Krishnan Mahadevan)
Fixed: GITHUB-2563: Skip test if its data provider provides no data (Krishnan Mahadevan)
Fixed: GITHUB-2535: TestResult.getEndMillis() returns 0 for skipped configuration - after upgrading testng to 7.0 + (Krishnan Mahadevan)
Expand Down
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -77,4 +77,11 @@
* @return the valude (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Expand Up @@ -40,4 +40,11 @@ public interface ITestOrConfiguration extends IParameterizable {
String getDescription();

void setDescription(String description);

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int getPriority();
}
Expand Up @@ -327,7 +327,7 @@ public int getPriority() {

@Override
public void setPriority(int priority) {
// ignored
m_method.setPriority(priority);
}

@Override
Expand All @@ -337,7 +337,7 @@ public int getInterceptedPriority() {

@Override
public void setInterceptedPriority(int priority) {
// ignored
m_method.setInterceptedPriority(priority);
}

@Override
Expand Down
Expand Up @@ -409,6 +409,7 @@ private void init() {
m_inheritGroupsFromTestClass = annotation.getInheritGroups();
setEnabled(annotation.getEnabled());
setDescription(annotation.getDescription());
setPriority(annotation.getPriority());
}

if (annotation != null && annotation.isFakeConfiguration()) {
Expand Down Expand Up @@ -503,6 +504,7 @@ public ConfigurationMethod clone() {
clone.setDescription(getDescription());
clone.setEnabled(getEnabled());
clone.setParameterInvocationCount(getParameterInvocationCount());
clone.setPriority(getPriority());
clone.m_inheritGroupsFromTestClass = inheritGroupsFromTestClass();

return clone;
Expand Down
17 changes: 9 additions & 8 deletions testng-core/src/main/java/org/testng/internal/MethodHelper.java
Expand Up @@ -289,16 +289,17 @@ private static Graph<ITestNGMethod> topologicalSort(
}
predecessors.addAll(Arrays.asList(methodsNamed));
}
if (XmlTest.isGroupBasedExecution(xmlTest)) {
String[] groupsDependedUpon = m.getGroupsDependedUpon();
if (groupsDependedUpon.length > 0) {
for (String group : groupsDependedUpon) {
ITestNGMethod[] methodsThatBelongToGroup =
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
}
// Should not be part of this commit. just added until GITHUB-2664 is solved.
// if (XmlTest.isGroupBasedExecution(xmlTest)) {
String[] groupsDependedUpon = m.getGroupsDependedUpon();
if (groupsDependedUpon.length > 0) {
for (String group : groupsDependedUpon) {
ITestNGMethod[] methodsThatBelongToGroup =
MethodGroupsHelper.findMethodsThatBelongToGroup(m, methods, group);
predecessors.addAll(Arrays.asList(methodsThatBelongToGroup));
}
}
// }

for (ITestNGMethod predecessor : predecessors) {
result.addPredecessor(m, predecessor);
Expand Down
Expand Up @@ -197,6 +197,7 @@ private static void finishInitialize(
result.setGroups(bs.getGroups());
result.setInheritGroups(bs.getInheritGroups());
result.setTimeOut(bs.getTimeOut());
result.setPriority(bs.getPriority());
}

public static List<Class<? extends IAnnotation>> getAllAnnotations() {
Expand Down
Expand Up @@ -109,6 +109,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterSuite.class) {
AfterSuite bs = (AfterSuite) a;
Expand Down Expand Up @@ -136,6 +137,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeTest.class) {
BeforeTest bs = (BeforeTest) a;
Expand Down Expand Up @@ -163,6 +165,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterTest.class) {
AfterTest bs = (AfterTest) a;
Expand Down Expand Up @@ -190,6 +193,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeGroups.class) {
BeforeGroups bs = (BeforeGroups) a;
Expand Down Expand Up @@ -218,6 +222,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterGroups.class) {
AfterGroups bs = (AfterGroups) a;
Expand Down Expand Up @@ -246,6 +251,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeClass.class) {
BeforeClass bs = (BeforeClass) a;
Expand Down Expand Up @@ -273,6 +279,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterClass.class) {
AfterClass bs = (AfterClass) a;
Expand Down Expand Up @@ -300,6 +307,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeMethod.class) {
BeforeMethod bs = (BeforeMethod) a;
Expand Down Expand Up @@ -327,6 +335,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
bs.firstTimeOnly(),
false,
bs.timeOut(),
bs.priority(),
bs.onlyForGroups());
} else if (annotationClass == IAfterMethod.class) {
AfterMethod bs = (AfterMethod) a;
Expand Down Expand Up @@ -354,6 +363,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
bs.lastTimeOnly(),
bs.timeOut(),
bs.priority(),
bs.onlyForGroups());
}

Expand Down Expand Up @@ -383,6 +393,7 @@ private IAnnotation createConfigurationTag(
boolean firstTimeOnly,
boolean lastTimeOnly,
long timeOut,
int priority,
String[] groupFilters) {
ConfigurationAnnotation result = new ConfigurationAnnotation();
result.setIsBeforeGroups(isBeforeGroups);
Expand Down Expand Up @@ -410,6 +421,7 @@ private IAnnotation createConfigurationTag(
result.setFirstTimeOnly(firstTimeOnly);
result.setLastTimeOnly(lastTimeOnly);
result.setTimeOut(timeOut);
result.setPriority(priority);

return result;
}
Expand Down
Expand Up @@ -62,6 +62,7 @@ public void setDescription(String description) {
m_description = description;
}

@Override
public int getPriority() {
return m_priority;
}
Expand Down
@@ -0,0 +1,73 @@
package test;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Arrays;
import java.util.List;
import org.testng.Assert;
import org.testng.TestNG;
import org.testng.annotations.Test;
import test.configuration.issue2663.ConfigurationMethodPrioritySampleTest;
import test.configuration.issue2663.ConfigurationMethodPriorityWithGroupDependencySampleTest;
import test.configuration.issue2663.ConfigurationMethodPriorityWithMethodDependencySampleTest;

public class ConfigurationMethodPriorityTest extends SimpleBaseTest {

@Test(description = "GITHUB-2663")
public void ensureThatPriorityWorksOnConfigurationMethods() {
TestNG testng = create(ConfigurationMethodPrioritySampleTest.class);
testng.run();
assertThat(testng.getStatus()).isEqualTo(0);
List<String> expectedLogs =
Arrays.asList(
"beforeSuiteB",
"beforeSuiteA",
"beforeClassB",
"beforeClassA",
"beforeMethodB",
"beforeMethodA",
"TestB",
"afterMethodB",
"afterMethodA",
"beforeMethodB",
"beforeMethodA",
"TestA",
"afterMethodB",
"afterMethodA",
"afterClassB",
"afterClassA",
"afterSuiteB",
"afterSuiteA");
assertThat(ConfigurationMethodPrioritySampleTest.logs).containsExactlyElementsOf(expectedLogs);
}

@Test(description = "GITHUB-2663")
public void ensureThatPriorityWorksOnConfigurationMethodsWithGroupDependency() {
List<String> expectedOrder1 =
Arrays.asList(
"s3", "s2", "s1", "t3", "t2", "t1", "c3", "c2", "c1", "m3", "m2", "m1", "test3", "m3",
"m2", "m1", "test2", "m3", "m2", "m1", "test1");
TestNG tng = create(ConfigurationMethodPriorityWithGroupDependencySampleTest.class);
InvokedMethodNameListener listener = new InvokedMethodNameListener();
tng.addListener(listener);
tng.run();
System.out.println(expectedOrder1);
System.out.println(listener.getSucceedMethodNames());
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
}

@Test(description = "GITHUB-2663")
public void ensureThatPriorityWorksOnConfigurationMethodsWithMethodDependency() {
List<String> expectedOrder1 =
Arrays.asList(
"s3", "s2", "s1", "t3", "t2", "t1", "c3", "c2", "c1", "m3", "m2", "m1", "test3", "m3",
"m2", "m1", "test2", "m3", "m2", "m1", "test1");
TestNG tng = create(ConfigurationMethodPriorityWithMethodDependencySampleTest.class);
InvokedMethodNameListener listener = new InvokedMethodNameListener();
tng.addListener(listener);
tng.run();
System.out.println(expectedOrder1);
System.out.println(listener.getSucceedMethodNames());
Assert.assertEquals(listener.getSucceedMethodNames(), expectedOrder1);
}
}

0 comments on commit d4be735

Please sign in to comment.