Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SuiteRunner could not be initial by default Configuration #2744

Merged
merged 1 commit into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.issue2743.SuiteRunnerIssueTestSample"));
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();
}
}