From aef12431fdc8b8cfa6750183271337fd948dba18 Mon Sep 17 00:00:00 2001 From: Martin Aldrin Date: Mon, 25 Oct 2021 14:53:30 +0200 Subject: [PATCH] Add support for Priority in Configuration Methods --- CHANGES.txt | 3 +- .../org/testng/annotations/AfterClass.java | 7 + .../org/testng/annotations/AfterGroups.java | 7 + .../org/testng/annotations/AfterMethod.java | 7 + .../org/testng/annotations/AfterSuite.java | 7 + .../org/testng/annotations/AfterTest.java | 7 + .../org/testng/annotations/BeforeClass.java | 7 + .../org/testng/annotations/BeforeGroups.java | 7 + .../org/testng/annotations/BeforeMethod.java | 7 + .../org/testng/annotations/BeforeSuite.java | 7 + .../org/testng/annotations/BeforeTest.java | 7 + .../annotations/ITestOrConfiguration.java | 7 + .../org/testng/internal/ClonedMethod.java | 4 +- .../testng/internal/ConfigurationMethod.java | 2 + .../org/testng/internal/MethodHelper.java | 17 +- .../annotations/AnnotationHelper.java | 1 + .../internal/annotations/JDK15TagFactory.java | 12 ++ .../annotations/TestOrConfiguration.java | 1 + .../test/ConfigurationMethodPriorityTest.java | 154 ++++++++++++++++++ .../ConfiguratinMethodPriorityBaseClass1.java | 54 ++++++ .../ConfiguratinMethodPriorityBaseClass2.java | 82 ++++++++++ ...iorityMultiLevelInheritanceSampleTest.java | 15 ++ ...ConfigurationMethodPrioritySampleTest.java | 93 +++++++++++ ...PriorityWithGroupDependencySampleTest.java | 134 +++++++++++++++ ...riorityWithMethodDependencySampleTest.java | 96 +++++++++++ testng-core/src/test/resources/testng.xml | 7 + 26 files changed, 741 insertions(+), 11 deletions(-) create mode 100644 testng-core/src/test/java/test/ConfigurationMethodPriorityTest.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass1.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass2.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPrioritySampleTest.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithGroupDependencySampleTest.java create mode 100644 testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithMethodDependencySampleTest.java diff --git a/CHANGES.txt b/CHANGES.txt index 4c4cbcff96..312ae321e7 100644 --- a/CHANGES.txt +++ b/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) diff --git a/testng-core-api/src/main/java/org/testng/annotations/AfterClass.java b/testng-core-api/src/main/java/org/testng/annotations/AfterClass.java index 19654eafdb..414e2087ca 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/AfterClass.java +++ b/testng-core-api/src/main/java/org/testng/annotations/AfterClass.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/AfterGroups.java b/testng-core-api/src/main/java/org/testng/annotations/AfterGroups.java index f2bc0d03e7..ee80c1d722 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/AfterGroups.java +++ b/testng-core-api/src/main/java/org/testng/annotations/AfterGroups.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/AfterMethod.java b/testng-core-api/src/main/java/org/testng/annotations/AfterMethod.java index fbe135fe0c..e642db5b24 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/AfterMethod.java +++ b/testng-core-api/src/main/java/org/testng/annotations/AfterMethod.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/AfterSuite.java b/testng-core-api/src/main/java/org/testng/annotations/AfterSuite.java index 5cf961a8f6..7fc6cd6bbe 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/AfterSuite.java +++ b/testng-core-api/src/main/java/org/testng/annotations/AfterSuite.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/AfterTest.java b/testng-core-api/src/main/java/org/testng/annotations/AfterTest.java index 53344b25b2..134b9af7b0 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/AfterTest.java +++ b/testng-core-api/src/main/java/org/testng/annotations/AfterTest.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/BeforeClass.java b/testng-core-api/src/main/java/org/testng/annotations/BeforeClass.java index a9d2afe8c5..7446c4fab3 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/BeforeClass.java +++ b/testng-core-api/src/main/java/org/testng/annotations/BeforeClass.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/BeforeGroups.java b/testng-core-api/src/main/java/org/testng/annotations/BeforeGroups.java index b25a18494c..5aaef4d6f3 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/BeforeGroups.java +++ b/testng-core-api/src/main/java/org/testng/annotations/BeforeGroups.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/BeforeMethod.java b/testng-core-api/src/main/java/org/testng/annotations/BeforeMethod.java index 7eec50329a..1f2f487559 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/BeforeMethod.java +++ b/testng-core-api/src/main/java/org/testng/annotations/BeforeMethod.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/BeforeSuite.java b/testng-core-api/src/main/java/org/testng/annotations/BeforeSuite.java index c1f3d86e5b..94685dd001 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/BeforeSuite.java +++ b/testng-core-api/src/main/java/org/testng/annotations/BeforeSuite.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/BeforeTest.java b/testng-core-api/src/main/java/org/testng/annotations/BeforeTest.java index fee1b66603..ad17326575 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/BeforeTest.java +++ b/testng-core-api/src/main/java/org/testng/annotations/BeforeTest.java @@ -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; } diff --git a/testng-core-api/src/main/java/org/testng/annotations/ITestOrConfiguration.java b/testng-core-api/src/main/java/org/testng/annotations/ITestOrConfiguration.java index eedc55d359..805f5e867d 100644 --- a/testng-core-api/src/main/java/org/testng/annotations/ITestOrConfiguration.java +++ b/testng-core-api/src/main/java/org/testng/annotations/ITestOrConfiguration.java @@ -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(); } diff --git a/testng-core/src/main/java/org/testng/internal/ClonedMethod.java b/testng-core/src/main/java/org/testng/internal/ClonedMethod.java index a7010a82ed..c49ad14381 100644 --- a/testng-core/src/main/java/org/testng/internal/ClonedMethod.java +++ b/testng-core/src/main/java/org/testng/internal/ClonedMethod.java @@ -327,7 +327,7 @@ public int getPriority() { @Override public void setPriority(int priority) { - // ignored + m_method.setPriority(priority); } @Override @@ -337,7 +337,7 @@ public int getInterceptedPriority() { @Override public void setInterceptedPriority(int priority) { - // ignored + m_method.setInterceptedPriority(priority); } @Override diff --git a/testng-core/src/main/java/org/testng/internal/ConfigurationMethod.java b/testng-core/src/main/java/org/testng/internal/ConfigurationMethod.java index a2b9f077be..cd17b1237d 100644 --- a/testng-core/src/main/java/org/testng/internal/ConfigurationMethod.java +++ b/testng-core/src/main/java/org/testng/internal/ConfigurationMethod.java @@ -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()) { @@ -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; diff --git a/testng-core/src/main/java/org/testng/internal/MethodHelper.java b/testng-core/src/main/java/org/testng/internal/MethodHelper.java index b4c826330d..27bc134652 100644 --- a/testng-core/src/main/java/org/testng/internal/MethodHelper.java +++ b/testng-core/src/main/java/org/testng/internal/MethodHelper.java @@ -289,16 +289,17 @@ private static Graph 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); diff --git a/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java b/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java index 3c13e0bd50..32c4f07037 100644 --- a/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java +++ b/testng-core/src/main/java/org/testng/internal/annotations/AnnotationHelper.java @@ -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> getAllAnnotations() { diff --git a/testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java b/testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java index bdca20e6be..fd74018c62 100644 --- a/testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java +++ b/testng-core/src/main/java/org/testng/internal/annotations/JDK15TagFactory.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -354,6 +363,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class annota false, bs.lastTimeOnly(), bs.timeOut(), + bs.priority(), bs.onlyForGroups()); } @@ -383,6 +393,7 @@ private IAnnotation createConfigurationTag( boolean firstTimeOnly, boolean lastTimeOnly, long timeOut, + int priority, String[] groupFilters) { ConfigurationAnnotation result = new ConfigurationAnnotation(); result.setIsBeforeGroups(isBeforeGroups); @@ -410,6 +421,7 @@ private IAnnotation createConfigurationTag( result.setFirstTimeOnly(firstTimeOnly); result.setLastTimeOnly(lastTimeOnly); result.setTimeOut(timeOut); + result.setPriority(priority); return result; } diff --git a/testng-core/src/main/java/org/testng/internal/annotations/TestOrConfiguration.java b/testng-core/src/main/java/org/testng/internal/annotations/TestOrConfiguration.java index f924b887e0..2f245c3dce 100644 --- a/testng-core/src/main/java/org/testng/internal/annotations/TestOrConfiguration.java +++ b/testng-core/src/main/java/org/testng/internal/annotations/TestOrConfiguration.java @@ -62,6 +62,7 @@ public void setDescription(String description) { m_description = description; } + @Override public int getPriority() { return m_priority; } diff --git a/testng-core/src/test/java/test/ConfigurationMethodPriorityTest.java b/testng-core/src/test/java/test/ConfigurationMethodPriorityTest.java new file mode 100644 index 0000000000..1ea9216438 --- /dev/null +++ b/testng-core/src/test/java/test/ConfigurationMethodPriorityTest.java @@ -0,0 +1,154 @@ +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.ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest; +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 expectedLogs = + Arrays.asList( + "beforeSuiteB", + "beforeSuiteA", + "beforeClassB", + "beforeClassA", + "beforeMethodB", + "beforeMethodA", + "testB", + "afterMethodB", + "afterMethodA", + "beforeMethodB", + "beforeMethodA", + "testA", + "afterMethodB", + "afterMethodA", + "afterClassB", + "afterClassA", + "afterSuiteB", + "afterSuiteA"); + String className = "test.configuration.issue2663.ConfigurationMethodPrioritySampleTest."; + expectedLogs.replaceAll(e -> className + e); + assertThat(ConfigurationMethodPrioritySampleTest.logs).containsExactlyElementsOf(expectedLogs); + } + + @Test(description = "GITHUB-2663") + public void ensureThatPriorityWorksOnConfigurationMethodsWithGroupDependency() { + List expectedOrder1 = + Arrays.asList( + "beforeSuite3", + "beforeSuite2", + "beforeSuite1", + "beforeTest3", + "beforeTest2", + "beforeTest1", + "beforeClass3", + "beforeClass2", + "beforeClass1", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test3", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test2", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test1"); + TestNG testng = create(ConfigurationMethodPriorityWithGroupDependencySampleTest.class); + testng.run(); + assertThat(testng.getStatus()).isEqualTo(0); + String className = + "test.configuration.issue2663.ConfigurationMethodPriorityWithGroupDependencySampleTest."; + expectedOrder1.replaceAll(e -> className + e); + Assert.assertEquals( + ConfigurationMethodPriorityWithGroupDependencySampleTest.logs, expectedOrder1); + } + + @Test(description = "GITHUB-2663") + public void ensureThatPriorityWorksOnConfigurationMethodsWithMethodDependency() { + List expectedOrder1 = + Arrays.asList( + "beforeSuite3", + "beforeSuite2", + "beforeSuite1", + "beforeTest3", + "beforeTest2", + "beforeTest1", + "beforeClass3", + "beforeClass2", + "beforeClass1", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test3", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test2", + "beforeMethod3", + "beforeMethod2", + "beforeMethod1", + "test1"); + TestNG testng = create(ConfigurationMethodPriorityWithMethodDependencySampleTest.class); + testng.run(); + assertThat(testng.getStatus()).isEqualTo(0); + String className = + "test.configuration.issue2663.ConfigurationMethodPriorityWithMethodDependencySampleTest."; + expectedOrder1.replaceAll(e -> className + e); + Assert.assertEquals( + ConfigurationMethodPriorityWithMethodDependencySampleTest.logs, expectedOrder1); + } + + @Test(description = "GITHUB-2663") + public void ensureThatPriorityWorksOnConfigurationMethodsMultiLevelInheritanc() { + String testClassName = + "test.configuration.issue2663.ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest."; + String baseClassName1 = "test.configuration.issue2663.ConfiguratinMethodPriorityBaseClass1."; + String baseClassName2 = "test.configuration.issue2663.ConfiguratinMethodPriorityBaseClass2."; + List expectedOrder1 = + Arrays.asList( + baseClassName1 + "beforeSuite3", + baseClassName2 + "beforeSuite2", + baseClassName2 + "beforeSuite1", + baseClassName1 + "beforeTest3", + baseClassName2 + "beforeTest2", + baseClassName2 + "beforeTest1", + baseClassName1 + "beforeClass3", + baseClassName2 + "beforeClass2", + baseClassName2 + "beforeClass1", + baseClassName1 + "beforeMethod3", + baseClassName2 + "beforeMethod2", + baseClassName2 + "beforeMethod1", + baseClassName1 + "test3", + baseClassName1 + "beforeMethod3", + baseClassName2 + "beforeMethod2", + baseClassName2 + "beforeMethod1", + baseClassName2 + "test2", + baseClassName1 + "beforeMethod3", + baseClassName2 + "beforeMethod2", + baseClassName2 + "beforeMethod1", + testClassName + "test1"); + TestNG testng = create(ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.class); + testng.run(); + assertThat(testng.getStatus()).isEqualTo(0); + + Assert.assertEquals( + ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.logs, expectedOrder1); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass1.java b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass1.java new file mode 100644 index 0000000000..68f3dc1f39 --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass1.java @@ -0,0 +1,54 @@ +package test.configuration.issue2663; + +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class ConfiguratinMethodPriorityBaseClass1 { + public static List logs = new ArrayList<>(); + + @BeforeSuite( + groups = {"g1"}, + priority = 2) + public void beforeSuite3() { + print(); + } + + @BeforeClass( + groups = {"g1"}, + priority = 2) + public void beforeClass3() { + print(); + } + + @BeforeTest( + groups = {"g1"}, + priority = 2) + public void beforeTest3() { + print(); + } + + @BeforeMethod( + groups = {"g1"}, + priority = 2) + public void beforeMethod3() { + print(); + } + + @Test(groups = {"g1"}) + public void test3() { + print(); + } + + protected synchronized void print() { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + String methodName = + stackTraceElements[2].getClassName() + "." + stackTraceElements[2].getMethodName(); + logs.add(methodName); + System.out.println(methodName); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass2.java b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass2.java new file mode 100644 index 0000000000..a77dff8c36 --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityBaseClass2.java @@ -0,0 +1,82 @@ +package test.configuration.issue2663; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class ConfiguratinMethodPriorityBaseClass2 extends ConfiguratinMethodPriorityBaseClass1 { + + @BeforeSuite( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeSuite2() { + print(); + } + + @BeforeSuite( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeSuite1() { + print(); + } + + @BeforeClass( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeClass2() { + print(); + } + + @BeforeClass( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeClass1() { + print(); + } + + @BeforeTest( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeTest2() { + print(); + } + + @BeforeTest( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeTest1() { + print(); + } + + @BeforeMethod( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeMethod2() { + print(); + } + + @BeforeMethod( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeMethod1() { + print(); + } + + @Test( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void test2() { + print(); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.java b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.java new file mode 100644 index 0000000000..3ec85526b7 --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest.java @@ -0,0 +1,15 @@ +package test.configuration.issue2663; + +import org.testng.annotations.Test; + +public class ConfiguratinMethodPriorityMultiLevelInheritanceSampleTest + extends ConfiguratinMethodPriorityBaseClass2 { + + @Test( + groups = {"g3"}, + dependsOnGroups = "g1", + priority = 1) + public void test1() { + print(); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPrioritySampleTest.java b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPrioritySampleTest.java new file mode 100644 index 0000000000..dec8becd22 --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPrioritySampleTest.java @@ -0,0 +1,93 @@ +package test.configuration.issue2663; + +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +public class ConfigurationMethodPrioritySampleTest { + public static List logs = new ArrayList<>(); + + @BeforeSuite(priority = 100) + public void beforeSuiteA() { + print(); + } + + @BeforeSuite(priority = 1) + public void beforeSuiteB() { + print(); + } + + @BeforeClass(priority = 100) + public void beforeClassA() { + print(); + } + + @BeforeClass(priority = 1) + public void beforeClassB() { + print(); + } + + @BeforeMethod(priority = 100) + public void beforeMethodA() { + print(); + } + + @BeforeMethod(priority = 1) + public void beforeMethodB() { + print(); + } + + @Test(priority = 100) + public void testA() { + print(); + } + + @Test(priority = 0) + public void testB() { + print(); + } + + @AfterSuite(priority = 100) + public void afterSuiteA() { + print(); + } + + @AfterSuite(priority = 1) + public void afterSuiteB() { + print(); + } + + @AfterClass(priority = 100) + public void afterClassA() { + print(); + } + + @AfterClass(priority = 1) + public void afterClassB() { + print(); + } + + @AfterMethod(priority = 100) + public void afterMethodA() { + print(); + } + + @AfterMethod(priority = 1) + public void afterMethodB() { + print(); + } + + private synchronized void print() { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + String methodName = + stackTraceElements[2].getClassName() + "." + stackTraceElements[2].getMethodName(); + logs.add(methodName); + System.out.println(methodName); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithGroupDependencySampleTest.java b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithGroupDependencySampleTest.java new file mode 100644 index 0000000000..075bbfd4bf --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithGroupDependencySampleTest.java @@ -0,0 +1,134 @@ +package test.configuration.issue2663; + +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class ConfigurationMethodPriorityWithGroupDependencySampleTest { + public static List logs = new ArrayList<>(); + + @BeforeSuite( + groups = {"g1"}, + priority = 2) + public void beforeSuite3() { + print(); + } + + @BeforeSuite( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeSuite2() { + print(); + } + + @BeforeSuite( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeSuite1() { + print(); + } + + @BeforeClass( + groups = {"g1"}, + priority = 2) + public void beforeClass3() { + print(); + } + + @BeforeClass( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeClass2() { + print(); + } + + @BeforeClass( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeClass1() { + print(); + } + + @BeforeTest( + groups = {"g1"}, + priority = 2) + public void beforeTest3() { + print(); + } + + @BeforeTest( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeTest2() { + print(); + } + + @BeforeTest( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeTest1() { + print(); + } + + @BeforeMethod( + groups = {"g1"}, + priority = 2) + public void beforeMethod3() { + print(); + } + + @BeforeMethod( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void beforeMethod2() { + print(); + } + + @BeforeMethod( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 1) + public void beforeMethod1() { + print(); + } + + @Test(groups = {"g1"}) + public void test3() { + print(); + } + + @Test( + groups = {"g2"}, + dependsOnGroups = "g1", + priority = 0) + public void test2() { + print(); + } + + @Test( + groups = {"g3"}, + dependsOnGroups = "g1", + priority = 1) + public void test1() { + print(); + } + + private synchronized void print() { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + String methodName = + stackTraceElements[2].getClassName() + "." + stackTraceElements[2].getMethodName(); + logs.add(methodName); + System.out.println(methodName); + } +} diff --git a/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithMethodDependencySampleTest.java b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithMethodDependencySampleTest.java new file mode 100644 index 0000000000..059400f6d2 --- /dev/null +++ b/testng-core/src/test/java/test/configuration/issue2663/ConfigurationMethodPriorityWithMethodDependencySampleTest.java @@ -0,0 +1,96 @@ +package test.configuration.issue2663; + +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class ConfigurationMethodPriorityWithMethodDependencySampleTest { + public static List logs = new ArrayList<>(); + + @BeforeSuite(priority = 2) + public void beforeSuite3() { + print(); + } + + @BeforeSuite(dependsOnMethods = "beforeSuite3", priority = 0) + public void beforeSuite2() { + print(); + } + + @BeforeSuite(dependsOnMethods = "beforeSuite3", priority = 1) + public void beforeSuite1() { + print(); + } + + @BeforeClass(priority = 2) + public void beforeClass3() { + print(); + } + + @BeforeClass(dependsOnMethods = "beforeClass3", priority = 0) + public void beforeClass2() { + print(); + } + + @BeforeClass(dependsOnMethods = "beforeClass3", priority = 1) + public void beforeClass1() { + print(); + } + + @BeforeTest(priority = 2) + public void beforeTest3() { + print(); + } + + @BeforeTest(dependsOnMethods = "beforeTest3", priority = 0) + public void beforeTest2() { + print(); + } + + @BeforeTest(dependsOnMethods = "beforeTest3", priority = 1) + public void beforeTest1() { + print(); + } + + @BeforeMethod(priority = 2) + public void beforeMethod3() { + print(); + } + + @BeforeMethod(dependsOnMethods = "beforeMethod3", priority = 0) + public void beforeMethod2() { + print(); + } + + @BeforeMethod(dependsOnMethods = "beforeMethod3", priority = 1) + public void beforeMethod1() { + print(); + } + + @Test(groups = {"g1"}) + public void test3() { + print(); + } + + @Test(dependsOnMethods = "test3", priority = 0) + public void test2() { + print(); + } + + @Test(dependsOnMethods = "test3", priority = 1) + public void test1() { + print(); + } + + private synchronized void print() { + StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); + String methodName = + stackTraceElements[2].getClassName() + "." + stackTraceElements[2].getMethodName(); + logs.add(methodName); + System.out.println(methodName); + } +} diff --git a/testng-core/src/test/resources/testng.xml b/testng-core/src/test/resources/testng.xml index 7a7eb4baad..59014b4835 100644 --- a/testng-core/src/test/resources/testng.xml +++ b/testng-core/src/test/resources/testng.xml @@ -996,4 +996,11 @@ + + + + + + +