Skip to content

Commit

Permalink
Remove deprecated JUnit related support in TestNG
Browse files Browse the repository at this point in the history
  • Loading branch information
krmahadevan committed Dec 27, 2023
1 parent 94bf011 commit 54b0732
Show file tree
Hide file tree
Showing 97 changed files with 39 additions and 3,155 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Current
7.10.0
Fixed: GITHUB-3022: Remove deprecated JUnit related support in TestNG (Krishnan Mahadevan)

7.9.0
Fixed: GITHUB-2019: Total thread count in testng parallel tests with dataproviders (Krishnan Mahadevan)
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ include(":testng-core")
include(":testng-core-api")
include(":testng-reflection-utils")
include(":testng-runner-api")
include(":testng-runner-junit4")
include(":testng-test-kit")
include(":testng-test-osgi")

Expand Down
2 changes: 0 additions & 2 deletions testng-ant/src/main/java/org/testng/TestNGAntTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ public void execute() throws BuildException {

protected List<String> createArguments() {
List<String> argv = Lists.newArrayList();
addBooleanIfTrue(argv, CommandLineArgs.JUNIT, mode == Mode.junit);
addBooleanIfTrue(argv, CommandLineArgs.MIXED, mode == Mode.mixed);
addBooleanIfTrue(
argv, CommandLineArgs.SKIP_FAILED_INVOCATION_COUNTS, m_skipFailedInvocationCounts);
addIntegerIfNotNull(argv, CommandLineArgs.LOG, m_verbose);
Expand Down
1 change: 0 additions & 1 deletion testng-bom/testng-bom-build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ dependencies {
api(projects.testngCore)
api(projects.testngReflectionUtils)
api(projects.testngRunnerApi)
api(projects.testngRunnerJunit4)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public String asXml(XmlSuite xmlSuite) {
if (isStringNotEmpty(xmlSuite.getTimeOut())) {
p.setProperty("time-out", xmlSuite.getTimeOut());
}
if (!DEFAULT_JUNIT.equals(xmlSuite.isJUnit())) {
p.setProperty(
"junit",
xmlSuite.isJUnit() != null ? xmlSuite.isJUnit().toString() : "false"); // TESTNG-141
}
XmlUtils.setProperty(
p,
"skipfailedinvocationcounts",
Expand Down Expand Up @@ -174,8 +169,6 @@ public String asXml(XmlTest xmlTest, String indent) {
xsb.setDefaultComment(defaultComment);
Properties p = new Properties();
p.setProperty("name", xmlTest.getName());
XmlUtils.setProperty(
p, "junit", Boolean.toString(xmlTest.isJUnit()), XmlSuite.DEFAULT_JUNIT.toString());
XmlUtils.setProperty(
p, "parallel", xmlTest.getParallel().toString(), XmlSuite.DEFAULT_PARALLEL.toString());
XmlUtils.setProperty(
Expand Down
33 changes: 0 additions & 33 deletions testng-core-api/src/main/java/org/testng/xml/XmlSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ public String toString() {

private FailurePolicy m_configFailurePolicy = DEFAULT_CONFIG_FAILURE_POLICY;

/** JUnit compatibility flag. */
public static final Boolean DEFAULT_JUNIT = Boolean.FALSE;

private Boolean m_isJUnit = DEFAULT_JUNIT;

/** Mixed mode flag. */
public static final Boolean DEFAULT_MIXED = Boolean.FALSE;

Expand Down Expand Up @@ -473,25 +468,6 @@ public void setThreadCount(int threadCount) {
m_threadCount = threadCount;
}

/** @return The JUnit compatibility flag. */
public Boolean isJUnit() {
return m_isJUnit;
}

/**
* Sets the JUnit compatibility flag.
*
* @param isJUnit The JUnit compatibility flag.
*/
public void setJUnit(Boolean isJUnit) {
m_isJUnit = isJUnit;
}

// For YAML
public void setJunit(Boolean j) {
setJUnit(j);
}

public Boolean skipFailedInvocationCounts() {
return m_skipFailedInvocationCounts;
}
Expand Down Expand Up @@ -609,7 +585,6 @@ public XmlSuite shallowCopy() {
result.setVerbose(getVerbose());
result.setXmlPackages(getXmlPackages());
result.setMethodSelectors(getMethodSelectors());
result.setJUnit(isJUnit()); // TESTNG-141
result.setSkipFailedInvocationCounts(skipFailedInvocationCounts());
result.setObjectFactoryClass(getObjectFactoryClass());
result.setAllowReturnValues(getAllowReturnValues());
Expand Down Expand Up @@ -715,7 +690,6 @@ public int hashCode() {
prime * result + ((m_configFailurePolicy == null) ? 0 : m_configFailurePolicy.hashCode());
result = prime * result + m_dataProviderThreadCount;
result = prime * result + ((m_fileName == null) ? 0 : m_fileName.hashCode());
result = prime * result + ((m_isJUnit == null) ? 0 : m_isJUnit.hashCode());
result = prime * result + ((m_listeners == null) ? 0 : m_listeners.hashCode());

result = prime * result + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode());
Expand Down Expand Up @@ -774,13 +748,6 @@ public boolean equals(Object obj) {
if (m_dataProviderThreadCount != other.m_dataProviderThreadCount) {
return f();
}
if (m_isJUnit == null) {
if (other.m_isJUnit != null) {
return f();
}
} else if (!m_isJUnit.equals(other.m_isJUnit)) {
return f();
}
if (m_listeners == null) {
if (other.m_listeners != null) {
return f();
Expand Down
51 changes: 4 additions & 47 deletions testng-core-api/src/main/java/org/testng/xml/XmlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class XmlTest implements Cloneable {
private XmlSuite m_suite;
private String m_name;
private Integer m_verbose = XmlSuite.DEFAULT_VERBOSE;
private Boolean m_isJUnit = XmlSuite.DEFAULT_JUNIT;
private int m_threadCount = -1;

private List<XmlClass> m_xmlClasses = Lists.newArrayList();
Expand Down Expand Up @@ -223,49 +222,21 @@ public int getVerbose() {
result = getSuite().getVerbose();
}

if (null != result) {
return result;
} else {
return 1;
}
return Optional.ofNullable(result).orElse(1);
}

public boolean getGroupByInstances() {
Boolean result = m_groupByInstances;
if (result == null || XmlSuite.DEFAULT_GROUP_BY_INSTANCES.equals(m_groupByInstances)) {
result = getSuite().getGroupByInstances();
}
if (result != null) {
return result;
} else {
return XmlSuite.DEFAULT_GROUP_BY_INSTANCES;
}
return Optional.ofNullable(result).orElse(XmlSuite.DEFAULT_GROUP_BY_INSTANCES);
}

public void setGroupByInstances(boolean f) {
m_groupByInstances = f;
}

/** @return Returns the isJUnit. */
public boolean isJUnit() {
Boolean result = m_isJUnit;
if (null == result || XmlSuite.DEFAULT_JUNIT.equals(result)) {
result = getSuite().isJUnit();
}

return result;
}

/** @param isJUnit The isJUnit to set. */
public void setJUnit(boolean isJUnit) {
m_isJUnit = isJUnit;
}

// For YAML
public void setJunit(boolean isJUnit) {
setJUnit(isJUnit);
}

public void setSkipFailedInvocationCounts(boolean skip) {
m_skipFailedInvocationCounts = skip;
}
Expand Down Expand Up @@ -421,12 +392,10 @@ public Object clone() {
result.setName(getName());
result.setIncludedGroups(getIncludedGroups());
result.setExcludedGroups(getExcludedGroups());
result.setJUnit(isJUnit());
result.setParallel(getParallel());
result.setThreadCount(getThreadCount());
result.setVerbose(getVerbose());
Map<String, String> localParameters = new HashMap<>();
localParameters.putAll(getLocalParameters());
Map<String, String> localParameters = new HashMap<>(getLocalParameters());
result.setParameters(localParameters);
result.setXmlPackages(getXmlPackages());
result.setTimeOut(getTimeOut());
Expand Down Expand Up @@ -460,14 +429,7 @@ public List<Integer> getInvocationNumbers(String method) {
}
}

List<Integer> result = m_failedInvocationNumbers.get(method);
if (result == null) {
// Don't use emptyList here since this list might end up receiving values if
// the test run fails.
return Lists.newArrayList();
} else {
return result;
}
return Optional.ofNullable(m_failedInvocationNumbers.get(method)).orElse(Lists.newArrayList());
}

public void setPreserveOrder(Boolean preserveOrder) {
Expand Down Expand Up @@ -527,7 +489,6 @@ public int hashCode() {
+ ((m_xmlGroups == null || m_xmlGroups.getRun() == null)
? 0
: m_xmlGroups.getRun().getIncludes().hashCode());
result = prime * result + ((m_isJUnit == null) ? 0 : m_isJUnit.hashCode());
result = prime * result + ((m_xmlGroups == null) ? 0 : m_xmlGroups.getDefines().hashCode());
result = prime * result + ((m_methodSelectors == null) ? 0 : m_methodSelectors.hashCode());
result = prime * result + ((m_name == null) ? 0 : m_name.hashCode());
Expand Down Expand Up @@ -579,10 +540,6 @@ public boolean equals(Object obj) {
if (other.m_failedInvocationNumbers != null) return XmlSuite.f();
} else if (!m_failedInvocationNumbers.equals(other.m_failedInvocationNumbers))
return XmlSuite.f();
if (m_isJUnit == null) {
if (other.m_isJUnit != null && !other.m_isJUnit.equals(XmlSuite.DEFAULT_JUNIT))
return XmlSuite.f();
} else if (!m_isJUnit.equals(other.m_isJUnit)) return XmlSuite.f();
if (m_methodSelectors == null) {
if (other.m_methodSelectors != null) return XmlSuite.f();
} else if (!m_methodSelectors.equals(other.m_methodSelectors)) return XmlSuite.f();
Expand Down
5 changes: 0 additions & 5 deletions testng-core/src/main/java/org/testng/CommandLineArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public class CommandLineArgs {
@Parameter(names = OUTPUT_DIRECTORY, description = "Output directory")
public String outputDirectory;

public static final String JUNIT = "-junit";

@Parameter(names = JUNIT, description = "JUnit mode")
public Boolean junit = Boolean.FALSE;

public static final String MIXED = "-mixed";

@Parameter(
Expand Down
42 changes: 0 additions & 42 deletions testng-core/src/main/java/org/testng/TestNG.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.testng.internal.objects.pojo.BasicAttributes;
import org.testng.internal.objects.pojo.CreationAttributes;
import org.testng.internal.thread.graph.SuiteWorkerFactory;
import org.testng.junit.JUnitTestFinder;
import org.testng.log4testng.Logger;
import org.testng.reporters.EmailableReporter;
import org.testng.reporters.EmailableReporter2;
Expand Down Expand Up @@ -130,12 +129,8 @@ public class TestNG {
protected List<XmlSuite> m_suites = Lists.newArrayList();
private List<XmlSuite> m_cmdlineSuites;
private String m_outputDir = DEFAULT_OUTPUTDIR;

private String[] m_includedGroups;
private String[] m_excludedGroups;

private Boolean m_isJUnit = XmlSuite.DEFAULT_JUNIT;
private Boolean m_isMixed = XmlSuite.DEFAULT_MIXED;
protected boolean m_useDefaultListeners = true;
private boolean m_failIfAllTestsSkipped = false;
private final List<String> m_listenersToSkipFromBeingWiredIn = new ArrayList<>();
Expand Down Expand Up @@ -546,11 +541,6 @@ private List<XmlSuite> createCommandLineSuitesForClasses(Class[] classes) {
if (test != null) {
suiteName = defaultIfStringEmpty(test.getSuiteName(), suiteName);
testName = defaultIfStringEmpty(test.getTestName(), testName);
} else {
if (m_isMixed && JUnitTestFinder.isJUnitTest(c)) {
isJUnit = true;
testName = c.getName();
}
}
XmlSuite xmlSuite = suites.get(suiteName);
if (xmlSuite == null) {
Expand All @@ -573,7 +563,6 @@ private List<XmlSuite> createCommandLineSuitesForClasses(Class[] classes) {
if (xmlTest == null) {
xmlTest = new XmlTest(xmlSuite);
xmlTest.setName(testName);
xmlTest.setJUnit(isJUnit);
}

xmlTest.getXmlClasses().add(xmlClasses[i]);
Expand Down Expand Up @@ -1332,10 +1321,6 @@ private void populateSuiteGraph(
* @param xmlSuite Xml Suite (and its children) for which {@code SuiteRunner}s are created
*/
private void createSuiteRunners(SuiteRunnerMap suiteRunnerMap /* OUT */, XmlSuite xmlSuite) {
if (null != m_isJUnit && !m_isJUnit.equals(XmlSuite.DEFAULT_JUNIT)) {
xmlSuite.setJUnit(m_isJUnit);
}

// If the skip flag was invoked on the command line, it
// takes precedence
if (null != m_skipFailedInvocationCounts) {
Expand Down Expand Up @@ -1529,8 +1514,6 @@ protected void configure(CommandLineArgs cla) {
setExcludedGroups(cla.excludedGroups);
setTestJar(cla.testJar);
setXmlPathInJar(cla.xmlPathInJar);
setJUnit(cla.junit);
setMixed(cla.mixed);
setSkipFailedInvocationCounts(cla.skipFailedInvocationCounts);
toggleFailureIfAllTestsWereSkipped(cla.failIfAllTestsSkipped);
setListenersToSkipFromBeingWiredInViaServiceLoaders(cla.spiListenersToSkip.split(","));
Expand Down Expand Up @@ -1698,7 +1681,6 @@ public void configure(Map cmdLineArgs) {
result.excludedGroups = (String) cmdLineArgs.get(CommandLineArgs.EXCLUDED_GROUPS);
result.testJar = (String) cmdLineArgs.get(CommandLineArgs.TEST_JAR);
result.xmlPathInJar = (String) cmdLineArgs.get(CommandLineArgs.XML_PATH_IN_JAR);
result.junit = (Boolean) cmdLineArgs.get(CommandLineArgs.JUNIT);
result.mixed = (Boolean) cmdLineArgs.get(CommandLineArgs.MIXED);
Object tmpValue = cmdLineArgs.get(CommandLineArgs.INCLUDE_ALL_DATA_DRIVEN_TESTS_WHEN_SKIPPING);
if (tmpValue != null) {
Expand Down Expand Up @@ -1828,23 +1810,6 @@ private IReporter newReporterInstance(ReporterConfig config) {
return reporter;
}

/**
* Specify if this run should be made in JUnit mode
*
* @param isJUnit - Specify if this run should be made in JUnit mode
*/
public void setJUnit(Boolean isJUnit) {
m_isJUnit = isJUnit;
}

/** @param isMixed Specify if this run should be made in mixed mode */
public void setMixed(Boolean isMixed) {
if (isMixed == null) {
return;
}
m_isMixed = isMixed;
}

/**
* Double check that the command line parameters are valid.
*
Expand Down Expand Up @@ -1873,13 +1838,6 @@ protected static void validateCommandLineParameters(CommandLineArgs args) {
&& (testNgXml == null || testNgXml.isEmpty())) {
throw new ParameterException("Groups option should be used with testclass option");
}

Boolean junit = args.junit;
Boolean mixed = args.mixed;
if (junit && mixed) {
throw new ParameterException(
CommandLineArgs.MIXED + " can't be combined with " + CommandLineArgs.JUNIT);
}
}

/** @return true if at least one test failed. */
Expand Down
Loading

0 comments on commit 54b0732

Please sign in to comment.