diff --git a/CHANGES.txt b/CHANGES.txt index fa0add3e7..b2bfd0dbe 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,7 @@ Current (7.11.0) +Fixed: GITHUB-3117: ListenerComparator doesn't work (Krishnan Mahadevan) + 7.10.1 Fixed: GITHUB-3110: Update from testng 7.9.0 to 7.10.0 break maven build with junit5 (Krishnan Mahadevan) diff --git a/testng-core/src/main/java/org/testng/TestNG.java b/testng-core/src/main/java/org/testng/TestNG.java index 0a72fcd57..b428ff932 100644 --- a/testng-core/src/main/java/org/testng/TestNG.java +++ b/testng-core/src/main/java/org/testng/TestNG.java @@ -1773,6 +1773,10 @@ public void configure(Map cmdLineArgs) { Boolean.parseBoolean( cmdLineArgs.getOrDefault(CommandLineArgs.GENERATE_RESULTS_PER_SUITE, false).toString()); + Optional.ofNullable(cmdLineArgs.get(CommandLineArgs.LISTENER_COMPARATOR)) + .map(Object::toString) + .ifPresent(it -> result.listenerComparator = it); + configure(result); } diff --git a/testng-core/src/test/java/test/listeners/ListenersTest.java b/testng-core/src/test/java/test/listeners/ListenersTest.java index 9a1911101..3b5f4fa7f 100644 --- a/testng-core/src/test/java/test/listeners/ListenersTest.java +++ b/testng-core/src/test/java/test/listeners/ListenersTest.java @@ -12,6 +12,7 @@ import java.util.Map; import org.assertj.core.api.Assertions; import org.assertj.core.api.SoftAssertions; +import org.testng.CommandLineArgs; import org.testng.ITestNGListener; import org.testng.TestNG; import org.testng.annotations.DataProvider; @@ -63,6 +64,14 @@ public class ListenersTest extends SimpleBaseTest { "test.listeners.issue2638.TestClassBSample.testMethod" }; + @Test(description = "GITHUB-3117") + public void ensureOrderingForExecutionListenersViaMaven() { + Ensure.orderingViaMap( + ExecutionListenerHolder.LOGS, + ExecutionListenerHolder.ALL, + ExecutionListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForExecutionListenersViaApi() { Ensure.orderingViaApi( @@ -71,6 +80,14 @@ public void ensureOrderingForExecutionListenersViaApi() { ExecutionListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForAlterSuiteListenersViaMaven() { + Ensure.orderingViaMap( + AlterSuiteListenerHolder.LOGS, + AlterSuiteListenerHolder.ALL, + AlterSuiteListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForAlterSuiteListenersViaApi() { Ensure.orderingViaApi( @@ -85,6 +102,12 @@ public void ensureOrderingForSuiteListenersViaApi() { SuiteListenerHolder.LOGS, SuiteListenerHolder.ALL, SuiteListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForSuiteListenersViaMaven() { + Ensure.orderingViaMap( + SuiteListenerHolder.LOGS, SuiteListenerHolder.ALL, SuiteListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForTestListenersViaApi() { Ensure.orderingViaApi( @@ -94,6 +117,15 @@ public void ensureOrderingForTestListenersViaApi() { TestListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForTestListenersViaMaven() { + Ensure.orderingViaMap( + ElaborateSampleTestCase.class, + TestListenerHolder.LOGS, + TestListenerHolder.ALL, + TestListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForInvokedListenersViaApi() { Ensure.orderingViaApi( @@ -102,6 +134,14 @@ public void ensureOrderingForInvokedListenersViaApi() { InvokedMethodListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForInvokedListenersViaMaven() { + Ensure.orderingViaMap( + InvokedMethodListenerHolder.LOGS, + InvokedMethodListenerHolder.ALL, + InvokedMethodListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForConfigurationListenersViaApi() { Ensure.orderingViaApi( @@ -111,12 +151,27 @@ public void ensureOrderingForConfigurationListenersViaApi() { ConfigurationListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForConfigurationListenersViaMaven() { + Ensure.orderingViaMap( + SimpleConfigTestCase.class, + ConfigurationListenerHolder.LOGS, + ConfigurationListenerHolder.ALL, + ConfigurationListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForClassListenersViaApi() { Ensure.orderingViaApi( ClassListenerHolder.LOGS, ClassListenerHolder.ALL, ClassListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForClassListenersViaMaven() { + Ensure.orderingViaMap( + ClassListenerHolder.LOGS, ClassListenerHolder.ALL, ClassListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForDataProviderListenersViaApi() { Ensure.orderingViaApi( @@ -126,6 +181,15 @@ public void ensureOrderingForDataProviderListenersViaApi() { DataProviderListenerHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForDataProviderListenersViaMaven() { + Ensure.orderingViaMap( + DataProviderSampleTestCase.class, + DataProviderListenerHolder.LOGS, + DataProviderListenerHolder.ALL, + DataProviderListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForDataProviderInterceptorsViaApi() { Ensure.orderingViaApi( @@ -135,6 +199,15 @@ public void ensureOrderingForDataProviderInterceptorsViaApi() { DataProviderInterceptorHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForDataProviderInterceptorsViaMaven() { + Ensure.orderingViaMap( + DataProviderSampleTestCase.class, + DataProviderListenerHolder.LOGS, + DataProviderListenerHolder.ALL, + DataProviderListenerHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForExecutionVisualisersViaApi() { Ensure.orderingViaApi( @@ -143,6 +216,14 @@ public void ensureOrderingForExecutionVisualisersViaApi() { ExecutionVisualiserHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForExecutionVisualisersViaMaven() { + Ensure.orderingViaMap( + ExecutionVisualiserHolder.LOGS, + ExecutionVisualiserHolder.ALL, + ExecutionVisualiserHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForMethodInterceptorsViaApi() { Ensure.orderingViaApi( @@ -151,6 +232,14 @@ public void ensureOrderingForMethodInterceptorsViaApi() { MethodInterceptorHolder.EXPECTED_LOGS); } + @Test(description = "GITHUB-3117") + public void ensureOrderingForMethodInterceptorsViaMaven() { + Ensure.orderingViaMap( + MethodInterceptorHolder.LOGS, + MethodInterceptorHolder.ALL, + MethodInterceptorHolder.EXPECTED_LOGS); + } + @Test(description = "GITHUB-2916") public void ensureOrderingForExecutionListenersViaXmlTag() { Ensure.orderingViaXmlTag( @@ -809,5 +898,25 @@ static void orderingViaApi( testng.run(); assertThat(logs).containsExactly(expected); } + + static void orderingViaMap( + List logs, List listeners, String[] expected) { + orderingViaMap(NormalSampleTestCase.class, logs, listeners, expected); + } + + static void orderingViaMap( + Class clazz, List logs, List listeners, String[] expected) { + logs.clear(); + TestNG testng = create(clazz); + listeners.forEach(testng::addListener); + testng.setUseDefaultListeners(false); + Map map = + Map.of( + CommandLineArgs.LISTENER_COMPARATOR, + AnnotationBackedListenerComparator.class.getName()); + testng.configure(map); + testng.run(); + assertThat(logs).containsExactly(expected); + } } }