Skip to content

Commit

Permalink
Streaming working of listener comparator
Browse files Browse the repository at this point in the history
Closes #3117

The listener comparator was NOT getting wired in 
when specified as a property in maven surefire plugin.
  • Loading branch information
krmahadevan committed Apr 28, 2024
1 parent fe24aa2 commit be199b4
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 4 additions & 0 deletions testng-core/src/main/java/org/testng/TestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
109 changes: 109 additions & 0 deletions testng-core/src/test/java/test/listeners/ListenersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -809,5 +898,25 @@ static void orderingViaApi(
testng.run();
assertThat(logs).containsExactly(expected);
}

static void orderingViaMap(
List<String> logs, List<ITestNGListener> listeners, String[] expected) {
orderingViaMap(NormalSampleTestCase.class, logs, listeners, expected);
}

static void orderingViaMap(
Class<?> clazz, List<String> logs, List<ITestNGListener> listeners, String[] expected) {
logs.clear();
TestNG testng = create(clazz);
listeners.forEach(testng::addListener);
testng.setUseDefaultListeners(false);
Map<String, String> map =
Map.of(
CommandLineArgs.LISTENER_COMPARATOR,
AnnotationBackedListenerComparator.class.getName());
testng.configure(map);
testng.run();
assertThat(logs).containsExactly(expected);
}
}
}

0 comments on commit be199b4

Please sign in to comment.