Skip to content

Commit

Permalink
Decouple SuiteRunner and TestRunner
Browse files Browse the repository at this point in the history
Closes #2928
  • Loading branch information
krmahadevan committed Jul 14, 2023
1 parent 1288058 commit 7dc15af
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Current

Fixed: GITHUB-2928: The constructor of TestRunner encountered NBC changes in 7.8.0 (Krishnan Mahadevan)
Fixed: GITHUB-581: Parameters of nested test suites are overridden(Krishnan Mahadevan)
Fixed: GITHUB-727 : Fixing data races (Krishnan Mahadevan)
Fixed: GITHUB-2913: Maps containing nulls can be incorrectly considered equal (Alex Heneveld)
Expand Down
10 changes: 10 additions & 0 deletions testng-core/src/main/java/org/testng/ISuiteRunnerListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.testng;

public interface ISuiteRunnerListener {

ITestListener getExitCodeListener();

void beforeInvocation(IInvokedMethod method, ITestResult testResult);

void afterInvocation(IInvokedMethod method, ITestResult testResult);
}
4 changes: 2 additions & 2 deletions testng-core/src/main/java/org/testng/SuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* <CODE>SuiteRunner</CODE> is responsible for running all the tests included in one suite. The test
* start is triggered by {@link #run()} method.
*/
public class SuiteRunner implements ISuite, IInvokedMethodListener {
public class SuiteRunner implements ISuite, ISuiteRunnerListener {

private static final String DEFAULT_OUTPUT_DIR = "test-output";

Expand Down Expand Up @@ -257,7 +257,7 @@ public void setReportResults(boolean reportResults) {
useDefaultListeners = reportResults;
}

ITestListener getExitCodeListener() {
public ITestListener getExitCodeListener() {
return exitCodeListener;
}

Expand Down
12 changes: 6 additions & 6 deletions testng-core/src/main/java/org/testng/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ protected TestRunner(
List<IClassListener> classListeners,
Comparator<ITestNGMethod> comparator,
DataProviderHolder otherHolder,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
this.comparator = comparator;
this.holder.merge(otherHolder);
init(
Expand All @@ -201,7 +201,7 @@ public TestRunner(
Collection<IInvokedMethodListener> invokedMethodListeners,
List<IClassListener> classListeners,
Comparator<ITestNGMethod> comparator,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
this.comparator = comparator;
init(
configuration,
Expand All @@ -223,7 +223,7 @@ public TestRunner(
boolean skipFailedInvocationCounts,
Collection<IInvokedMethodListener> invokedMethodListeners,
List<IClassListener> classListeners,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
this.comparator = Systematiser.getComparator();
init(
configuration,
Expand All @@ -246,7 +246,7 @@ private void init(
boolean skipFailedInvocationCounts,
Collection<IInvokedMethodListener> invokedMethodListeners,
List<IClassListener> classListeners,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
m_configuration = configuration;
m_xmlTest = test;
m_suite = suite;
Expand All @@ -257,8 +257,8 @@ private void init(
m_objectFactory = suite.getObjectFactory();
setVerbose(test.getVerbose());
if (suiteRunner == null) {
if (suite instanceof SuiteRunner) {
setExitCodeListener(((SuiteRunner) suite).getExitCodeListener());
if (suite instanceof ISuiteRunnerListener) {
setExitCodeListener(((ISuiteRunnerListener) suite).getExitCodeListener());
}
} else {
setExitCodeListener(suiteRunner.getExitCodeListener());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.Set;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ISuiteRunnerListener;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.SuiteRunState;
import org.testng.SuiteRunner;
import org.testng.collections.Maps;
import org.testng.internal.IConfiguration;
import org.testng.internal.ITestResultNotifier;
Expand All @@ -34,15 +34,15 @@ class BaseInvoker {
// Instead we now would be using this special object.
protected final Object NULL_OBJECT = new Object();

private final SuiteRunner suiteRunner;
private final ISuiteRunnerListener suiteRunner;

public BaseInvoker(
ITestResultNotifier notifier,
Collection<IInvokedMethodListener> invokedMethodListeners,
ITestContext testContext,
SuiteRunState suiteState,
IConfiguration configuration,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
this.m_notifier = notifier;
this.m_invokedMethodListeners = invokedMethodListeners;
this.m_testContext = testContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import org.testng.IConfigurable;
import org.testng.IConfigurationListener;
import org.testng.IInvokedMethodListener;
import org.testng.ISuiteRunnerListener;
import org.testng.ITestClass;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.SuiteRunState;
import org.testng.SuiteRunner;
import org.testng.TestNGException;
import org.testng.annotations.IConfigurationAnnotation;
import org.testng.collections.Maps;
Expand Down Expand Up @@ -69,7 +69,7 @@ public ConfigInvoker(
SuiteRunState suiteState,
IConfiguration configuration,
IConfigurationListener internalConfigurationListener,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
super(notifier, invokedMethodListeners, testContext, suiteState, configuration, suiteRunner);
this.m_continueOnFailedConfiguration =
testContext.getSuite().getXmlSuite().getConfigFailurePolicy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import org.testng.IClassListener;
import org.testng.IConfigurationListener;
import org.testng.IInvokedMethodListener;
import org.testng.ISuiteRunnerListener;
import org.testng.ITestContext;
import org.testng.ITestNGMethod;
import org.testng.SuiteRunState;
import org.testng.SuiteRunner;
import org.testng.internal.IConfiguration;
import org.testng.internal.ITestResultNotifier;

Expand Down Expand Up @@ -41,7 +41,7 @@ public Invoker(
List<IClassListener> classListeners,
DataProviderHolder holder,
IConfigurationListener internalConfigurationListener,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
m_configInvoker =
new ConfigInvoker(
notifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.testng.IInvokedMethodListener;
import org.testng.IRetryAnalyzer;
import org.testng.ISuite;
import org.testng.ISuiteRunnerListener;
import org.testng.ITestClass;
import org.testng.ITestContext;
import org.testng.ITestListener;
Expand Down Expand Up @@ -69,7 +70,7 @@ public TestInvoker(
List<IClassListener> m_classListeners,
boolean m_skipFailedInvocationCounts,
ConfigInvoker invoker,
SuiteRunner suiteRunner) {
ISuiteRunnerListener suiteRunner) {
super(
m_notifier,
m_invokedMethodListeners,
Expand Down

0 comments on commit 7dc15af

Please sign in to comment.