Skip to content

Commit

Permalink
SuiteRunner could not be initial by default Configuration
Browse files Browse the repository at this point in the history
Fixes #2743
  • Loading branch information
bj-9527 committed Mar 22, 2022
1 parent e9a6c4f commit 3103d55
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Current
7.6.0
Fixed: GITHUB-2743: SuiteRunner could not be initial by default Configuration (Nan Liang)
Fixed: GITHUB-2729: beforeConfiguration() listener method should be invoked for skipped configurations as well(Nan Liang)
Fixed: assertEqualsNoOrder for Collection and Iterators size check was missing (Adam Kaczmarek)
Fixed: GITHUB-2709: Testnames not working together with suites in suite (Martin Aldrin)
Expand Down
4 changes: 4 additions & 0 deletions testng-core/src/main/java/org/testng/SuiteRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.testng.internal.invokers.IInvocationStatus;
import org.testng.internal.invokers.IInvoker;
import org.testng.internal.invokers.InvokedMethod;
import org.testng.internal.objects.ObjectFactoryImpl;
import org.testng.internal.thread.ThreadUtil;
import org.testng.reporters.JUnitXMLReporter;
import org.testng.reporters.TestHTMLReporter;
Expand Down Expand Up @@ -148,6 +149,9 @@ private void init(
List<IMethodInterceptor> localMethodInterceptors =
Optional.ofNullable(methodInterceptors).orElse(Lists.newArrayList());
setOutputDir(outputDir);
if (configuration.getObjectFactory() == null) {
configuration.setObjectFactory(new ObjectFactoryImpl());
}
if (suite.getObjectFactoryClass() == null) {
objectFactory = configuration.getObjectFactory();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.Arrays;
import org.testng.Assert;
import org.testng.TestNG;
import org.testng.annotations.Test;
import test.configuration.issue2743.SuiteRunnerIssueTestSample;
import test.configuration.sample.ConfigurationTestSample;
import test.configuration.sample.ExternalConfigurationClassSample;
import test.configuration.sample.MethodCallOrderTestSample;
Expand All @@ -29,4 +31,12 @@ public void testSuite() {
testConfiguration(SuiteTestSample.class);
Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), SuiteTestSample.m_order);
}

@Test
public void testSuiteRunnerWithDefaultConfiguration() {
TestNG testNG = create(SuiteRunnerIssueTestSample.class);
testNG.run();

Assert.assertEquals(testNG.getStatus(), 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package test.configuration.issue2743;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import org.testng.IClassListener;
import org.testng.IInvokedMethodListener;
import org.testng.ISuite;
import org.testng.ITestNGMethod;
import org.testng.ITestRunnerFactory;
import org.testng.SuiteRunner;
import org.testng.TestRunner;
import org.testng.annotations.Test;
import org.testng.internal.Configuration;
import org.testng.internal.IConfiguration;
import org.testng.reporters.JUnitXMLReporter;
import org.testng.reporters.TestHTMLReporter;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

public class SuiteRunnerIssueTestSample {

@Test
public void suiteRunnerSample() {
XmlSuite suite = new XmlSuite();
suite.setName("TestSuite");
XmlTest test = new XmlTest(suite);
test.setName("ChildTests");
List<XmlClass> classes = new ArrayList<>();
classes.add(new XmlClass("test.configuration.suites.IssueTest"));
test.setXmlClasses(classes);

final IConfiguration configuration = new Configuration();
final boolean useDefaultListeners = true;

SuiteRunner suiteRunner =
new SuiteRunner(
configuration,
suite,
"outputDir",
new ITestRunnerFactory() {

@Override
public TestRunner newTestRunner(
ISuite suite,
XmlTest xmlTest,
Collection<IInvokedMethodListener> listeners,
List<IClassListener> classListeners) {
TestRunner runner =
new TestRunner(
configuration,
suite,
xmlTest,
false /* skipFailedInvocationCounts */,
listeners,
classListeners);
if (useDefaultListeners) {
runner.addListener(new TestHTMLReporter());
runner.addListener(new JUnitXMLReporter());
}

return runner;
}
},
useDefaultListeners,
Comparator.comparingInt(ITestNGMethod::getPriority));
suiteRunner.run();
}
}

0 comments on commit 3103d55

Please sign in to comment.