From 883e0ee471932eab903c18f2d59caf583211a417 Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Wed, 27 Dec 2023 20:19:10 +0530 Subject: [PATCH] Remove deprecated JUnit related support in TestNG Closes #3022 --- settings.gradle.kts | 1 - .../main/java/org/testng/TestNGAntTask.java | 2 - testng-bom/testng-bom-build.gradle.kts | 1 - .../java/org/testng/xml/DefaultXmlWeaver.java | 7 - .../main/java/org/testng/xml/XmlSuite.java | 33 --- .../src/main/java/org/testng/xml/XmlTest.java | 51 +--- .../main/java/org/testng/CommandLineArgs.java | 5 - .../src/main/java/org/testng/TestNG.java | 42 --- .../src/main/java/org/testng/TestRunner.java | 110 +------ .../java/org/testng/internal/ClassImpl.java | 11 - .../main/java/org/testng/internal/Yaml.java | 15 +- .../org/testng/junit/IJUnitTestRunner.java | 52 ---- .../org/testng/junit/JUnit3TestClass.java | 14 - .../org/testng/junit/JUnit3TestMethod.java | 33 --- .../testng/junit/JUnit3TestRecognizer.java | 40 --- .../junit/JUnit4ConfigurationMethod.java | 33 --- .../org/testng/junit/JUnit4SpockMethod.java | 49 ---- .../org/testng/junit/JUnit4TestClass.java | 22 -- .../org/testng/junit/JUnit4TestMethod.java | 65 ----- .../testng/junit/JUnit4TestRecognizer.java | 32 --- .../org/testng/junit/JUnit4TestRunner.java | 272 ------------------ .../org/testng/junit/JUnitMethodFinder.java | 129 --------- .../java/org/testng/junit/JUnitTestClass.java | 150 ---------- .../org/testng/junit/JUnitTestFinder.java | 55 ---- .../org/testng/junit/JUnitTestMethod.java | 43 --- .../org/testng/junit/JUnitTestRecognizer.java | 10 - .../org/testng/junit/JUnitTestRunner.java | 269 ----------------- .../org/testng/reporters/FailedReporter.java | 1 - .../org/testng/xml/TestNGContentHandler.java | 19 +- .../test/groovy/EasyJUnitGroovySample.groovy | 17 -- .../test/groovy/test/groovy/GroovyTest.groovy | 26 -- .../SpecialNameJUnitGroovySample.groovy | 17 -- .../src/test/java/ConverterSample2.java | 24 -- .../src/test/java/ConverterSample4.java | 69 ----- testng-core/src/test/java/test/BaseTest.java | 4 - .../src/test/java/test/CommandLineTest.java | 175 ----------- .../src/test/java/test/JUnit4Test.java | 92 ------ .../src/test/java/test/JUnitTest1.java | 115 -------- .../test/java/test/JUnitTestClassLoader.java | 119 -------- .../test/github1405/JUnitTestClassSample.java | 8 - .../github1405/TestExclusionOfMainMethod.java | 26 -- .../src/test/java/test/junit/BaseTest.java | 40 --- .../java/test/junit/JUnitConstructorTest.java | 35 --- .../test/java/test/junit/JUnitEmptyTest.java | 17 -- .../src/test/java/test/junit/MainSuite.java | 16 -- .../src/test/java/test/junit/SetNameTest.java | 25 -- .../test/junit/SetUpExceptionSampleTest.java | 16 -- .../java/test/junit/SetUpExceptionTest.java | 19 -- .../src/test/java/test/junit/Suite1.java | 17 -- .../src/test/java/test/junit/Suite2.java | 14 - .../src/test/java/test/junit/Suite3.java | 12 - .../src/test/java/test/junit/Suite4.java | 13 - .../src/test/java/test/junit/TestAa.java | 8 - .../src/test/java/test/junit/TestAb.java | 8 - .../src/test/java/test/junit/TestAc.java | 8 - .../src/test/java/test/junit/TestAd.java | 8 - .../src/test/java/test/junit/TestAe.java | 8 - .../src/test/java/test/junit/TestAf.java | 8 - .../test/java/test/junit/testsetup/ATest.java | 11 - .../test/java/test/junit/testsetup/Data.java | 5 - .../test/junit/testsetup/LayerATestSuite.java | 15 - .../junit/testsetup/LoggingTestSuite.java | 21 -- .../java/test/junit/testsetup/SmokeSuite.java | 27 -- .../testsetup/TestSuiteContainerWrapper.java | 40 --- .../test/junit4/BeforeClassJUnit4Sample.java | 23 -- .../test/junit4/ClassRuleJUnit4Sample.java | 27 -- .../test/java/test/junit4/InheritedTest.java | 4 - .../test/java/test/junit4/JUnit4Child.java | 9 - .../test/junit4/JUnit4ParameterizedTest.java | 54 ---- .../test/java/test/junit4/JUnit4Sample1.java | 10 - .../test/java/test/junit4/JUnit4Sample2.java | 34 --- .../java/test/junit4/JUnit4SampleSuite.java | 14 - .../junit4/issue2792/TestClassSample.java | 9 - .../TestContextGatheringListener.java | 31 -- .../Issue323JUnitInvocationListener.java | 21 -- .../junit4/listeners/Issue323TestRunner.java | 21 -- .../junit4/listeners/Issue323TestSample.java | 8 - .../src/test/java/test/mixed/JUnit3Test1.java | 15 - .../src/test/java/test/mixed/JUnit4Test1.java | 13 - .../src/test/java/test/mixed/MixedTest.java | 72 ----- .../test/java/test/mixed/TestNGGroups.java | 12 - .../src/test/java/test/mixed/TestNGTest1.java | 13 - .../java/test/reports/issue2069/Dummy1.java | 13 - .../java/test/reports/issue2069/Dummy2.java | 8 - .../java/test/reports/issue2069/Dummy3.java | 18 -- .../java/test/reports/issue2069/Dummy4.java | 9 - .../test/reports/issue2069/IssueTest.java | 44 --- .../src/test/resources/junit-suite.xml | 11 - testng-core/src/test/resources/testng-all.xml | 6 +- testng-core/src/test/resources/testng.xml | 14 - testng-core/src/test/resources/yaml/a2.xml | 6 +- testng-core/src/test/resources/yaml/a3-a.xml | 2 +- testng-core/src/test/resources/yaml/a3-b.xml | 2 +- testng-core/testng-core-build.gradle.kts | 5 - .../testng-runner-junit4-build.gradle.kts | 8 - testng/testng-build.gradle.kts | 7 - 96 files changed, 37 insertions(+), 3155 deletions(-) delete mode 100644 testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4SpockMethod.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitTestClass.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java delete mode 100644 testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java delete mode 100644 testng-core/src/test/groovy/test/groovy/EasyJUnitGroovySample.groovy delete mode 100644 testng-core/src/test/groovy/test/groovy/SpecialNameJUnitGroovySample.groovy delete mode 100644 testng-core/src/test/java/ConverterSample2.java delete mode 100644 testng-core/src/test/java/ConverterSample4.java delete mode 100644 testng-core/src/test/java/test/CommandLineTest.java delete mode 100644 testng-core/src/test/java/test/JUnit4Test.java delete mode 100644 testng-core/src/test/java/test/JUnitTest1.java delete mode 100644 testng-core/src/test/java/test/JUnitTestClassLoader.java delete mode 100644 testng-core/src/test/java/test/github1405/JUnitTestClassSample.java delete mode 100644 testng-core/src/test/java/test/github1405/TestExclusionOfMainMethod.java delete mode 100644 testng-core/src/test/java/test/junit/BaseTest.java delete mode 100644 testng-core/src/test/java/test/junit/JUnitConstructorTest.java delete mode 100644 testng-core/src/test/java/test/junit/JUnitEmptyTest.java delete mode 100644 testng-core/src/test/java/test/junit/MainSuite.java delete mode 100644 testng-core/src/test/java/test/junit/SetNameTest.java delete mode 100644 testng-core/src/test/java/test/junit/SetUpExceptionSampleTest.java delete mode 100644 testng-core/src/test/java/test/junit/SetUpExceptionTest.java delete mode 100644 testng-core/src/test/java/test/junit/Suite1.java delete mode 100644 testng-core/src/test/java/test/junit/Suite2.java delete mode 100644 testng-core/src/test/java/test/junit/Suite3.java delete mode 100644 testng-core/src/test/java/test/junit/Suite4.java delete mode 100644 testng-core/src/test/java/test/junit/TestAa.java delete mode 100644 testng-core/src/test/java/test/junit/TestAb.java delete mode 100644 testng-core/src/test/java/test/junit/TestAc.java delete mode 100644 testng-core/src/test/java/test/junit/TestAd.java delete mode 100644 testng-core/src/test/java/test/junit/TestAe.java delete mode 100644 testng-core/src/test/java/test/junit/TestAf.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/ATest.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/Data.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/LayerATestSuite.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/LoggingTestSuite.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/SmokeSuite.java delete mode 100644 testng-core/src/test/java/test/junit/testsetup/TestSuiteContainerWrapper.java delete mode 100644 testng-core/src/test/java/test/junit4/BeforeClassJUnit4Sample.java delete mode 100644 testng-core/src/test/java/test/junit4/ClassRuleJUnit4Sample.java delete mode 100644 testng-core/src/test/java/test/junit4/InheritedTest.java delete mode 100644 testng-core/src/test/java/test/junit4/JUnit4Child.java delete mode 100644 testng-core/src/test/java/test/junit4/JUnit4ParameterizedTest.java delete mode 100644 testng-core/src/test/java/test/junit4/JUnit4Sample1.java delete mode 100644 testng-core/src/test/java/test/junit4/JUnit4Sample2.java delete mode 100644 testng-core/src/test/java/test/junit4/JUnit4SampleSuite.java delete mode 100644 testng-core/src/test/java/test/junit4/issue2792/TestClassSample.java delete mode 100644 testng-core/src/test/java/test/junit4/issue2792/TestContextGatheringListener.java delete mode 100644 testng-core/src/test/java/test/junit4/listeners/Issue323JUnitInvocationListener.java delete mode 100644 testng-core/src/test/java/test/junit4/listeners/Issue323TestRunner.java delete mode 100644 testng-core/src/test/java/test/junit4/listeners/Issue323TestSample.java delete mode 100644 testng-core/src/test/java/test/mixed/JUnit3Test1.java delete mode 100644 testng-core/src/test/java/test/mixed/JUnit4Test1.java delete mode 100644 testng-core/src/test/java/test/mixed/MixedTest.java delete mode 100644 testng-core/src/test/java/test/mixed/TestNGGroups.java delete mode 100644 testng-core/src/test/java/test/mixed/TestNGTest1.java delete mode 100755 testng-core/src/test/java/test/reports/issue2069/Dummy1.java delete mode 100755 testng-core/src/test/java/test/reports/issue2069/Dummy2.java delete mode 100755 testng-core/src/test/java/test/reports/issue2069/Dummy3.java delete mode 100755 testng-core/src/test/java/test/reports/issue2069/Dummy4.java delete mode 100644 testng-core/src/test/java/test/reports/issue2069/IssueTest.java delete mode 100644 testng-core/src/test/resources/junit-suite.xml delete mode 100644 testng-runner-junit4/testng-runner-junit4-build.gradle.kts diff --git a/settings.gradle.kts b/settings.gradle.kts index 64cc60fccf..c5946b8416 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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") diff --git a/testng-ant/src/main/java/org/testng/TestNGAntTask.java b/testng-ant/src/main/java/org/testng/TestNGAntTask.java index 6ef5967d94..cbd2934c21 100644 --- a/testng-ant/src/main/java/org/testng/TestNGAntTask.java +++ b/testng-ant/src/main/java/org/testng/TestNGAntTask.java @@ -560,8 +560,6 @@ public void execute() throws BuildException { protected List createArguments() { List 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); diff --git a/testng-bom/testng-bom-build.gradle.kts b/testng-bom/testng-bom-build.gradle.kts index 404bd17f22..14309a85cc 100644 --- a/testng-bom/testng-bom-build.gradle.kts +++ b/testng-bom/testng-bom-build.gradle.kts @@ -14,6 +14,5 @@ dependencies { api(projects.testngCore) api(projects.testngReflectionUtils) api(projects.testngRunnerApi) - api(projects.testngRunnerJunit4) } } diff --git a/testng-core-api/src/main/java/org/testng/xml/DefaultXmlWeaver.java b/testng-core-api/src/main/java/org/testng/xml/DefaultXmlWeaver.java index 5beb32a632..df59c6bde1 100644 --- a/testng-core-api/src/main/java/org/testng/xml/DefaultXmlWeaver.java +++ b/testng-core-api/src/main/java/org/testng/xml/DefaultXmlWeaver.java @@ -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", @@ -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( diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java b/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java index 4787323365..3ad1831dc2 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlSuite.java @@ -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; @@ -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; } @@ -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()); @@ -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()); @@ -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(); diff --git a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java index e408e0f327..9556a23ac4 100644 --- a/testng-core-api/src/main/java/org/testng/xml/XmlTest.java +++ b/testng-core-api/src/main/java/org/testng/xml/XmlTest.java @@ -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 m_xmlClasses = Lists.newArrayList(); @@ -223,11 +222,7 @@ public int getVerbose() { result = getSuite().getVerbose(); } - if (null != result) { - return result; - } else { - return 1; - } + return Optional.ofNullable(result).orElse(1); } public boolean getGroupByInstances() { @@ -235,37 +230,13 @@ public boolean getGroupByInstances() { 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; } @@ -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 localParameters = new HashMap<>(); - localParameters.putAll(getLocalParameters()); + Map localParameters = new HashMap<>(getLocalParameters()); result.setParameters(localParameters); result.setXmlPackages(getXmlPackages()); result.setTimeOut(getTimeOut()); @@ -460,14 +429,7 @@ public List getInvocationNumbers(String method) { } } - List 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) { @@ -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()); @@ -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(); diff --git a/testng-core/src/main/java/org/testng/CommandLineArgs.java b/testng-core/src/main/java/org/testng/CommandLineArgs.java index 066ce6a926..7f2cce1ca3 100644 --- a/testng-core/src/main/java/org/testng/CommandLineArgs.java +++ b/testng-core/src/main/java/org/testng/CommandLineArgs.java @@ -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( diff --git a/testng-core/src/main/java/org/testng/TestNG.java b/testng-core/src/main/java/org/testng/TestNG.java index cda2756a87..aef4d7e9ac 100644 --- a/testng-core/src/main/java/org/testng/TestNG.java +++ b/testng-core/src/main/java/org/testng/TestNG.java @@ -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; @@ -130,12 +129,8 @@ public class TestNG { protected List m_suites = Lists.newArrayList(); private List 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 m_listenersToSkipFromBeingWiredIn = new ArrayList<>(); @@ -546,11 +541,6 @@ private List 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) { @@ -573,7 +563,6 @@ private List createCommandLineSuitesForClasses(Class[] classes) { if (xmlTest == null) { xmlTest = new XmlTest(xmlSuite); xmlTest.setName(testName); - xmlTest.setJUnit(isJUnit); } xmlTest.getXmlClasses().add(xmlClasses[i]); @@ -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) { @@ -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(",")); @@ -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) { @@ -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. * @@ -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. */ diff --git a/testng-core/src/main/java/org/testng/TestRunner.java b/testng-core/src/main/java/org/testng/TestRunner.java index de9a3f609b..f7aa0f549e 100644 --- a/testng-core/src/main/java/org/testng/TestRunner.java +++ b/testng-core/src/main/java/org/testng/TestRunner.java @@ -15,11 +15,9 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.PriorityBlockingQueue; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.Stream; -import javax.annotation.Nonnull; import org.testng.collections.Lists; import org.testng.collections.Maps; import org.testng.collections.Sets; @@ -56,16 +54,12 @@ import org.testng.internal.invokers.ConfigMethodArguments.Builder; import org.testng.internal.invokers.IInvoker; import org.testng.internal.invokers.Invoker; -import org.testng.internal.invokers.TestMethodWorker; import org.testng.internal.objects.IObjectDispenser; -import org.testng.junit.IJUnitTestRunner; -import org.testng.log4testng.Logger; import org.testng.thread.IThreadWorkerFactory; import org.testng.thread.IWorker; import org.testng.util.Strings; import org.testng.util.TimeUtils; import org.testng.xml.XmlClass; -import org.testng.xml.XmlInclude; import org.testng.xml.XmlPackage; import org.testng.xml.XmlTest; @@ -77,7 +71,6 @@ public class TestRunner IConfigEavesdropper { private static final String DEFAULT_PROP_OUTPUT_DIR = "test-output"; - private static final Logger LOGGER = Logger.getLogger(TestRunner.class); private final Comparator comparator; private ISuite m_suite; @@ -99,7 +92,6 @@ public class TestRunner private final IConfigurationListener m_confListener = new ConfigurationListener(); - private Collection m_invokedMethodListeners = Lists.newArrayList(); private final Map, IClassListener> m_classListeners = Maps.newLinkedHashMap(); private final DataProviderHolder holder = new DataProviderHolder(); @@ -268,7 +260,7 @@ private void init( ? new PreserveOrderMethodInterceptor() : new InstanceOrderingMethodInterceptor(); m_methodInterceptors = new ArrayList<>(); - // Add the built in interceptor as the first interceptor. That way we let our users determine + // Add the built-in interceptor as the first interceptor. That way we let our users determine // the final order // by plugging in their own custom interceptors as well. m_methodInterceptors.add(builtinInterceptor); @@ -279,7 +271,6 @@ private void init( } m_annotationFinder = annotationFinder; - m_invokedMethodListeners = invokedMethodListeners; m_classListeners.clear(); for (IClassListener classListener : classListeners) { m_classListeners.put(classListener.getClass(), classListener); @@ -349,10 +340,7 @@ private void init() { initRunInfo(m_xmlTest); // Init methods and class map - // JUnit behavior is different and doesn't need this initialization step - if (!m_xmlTest.isJUnit()) { - initMethods(); - } + initMethods(); initListeners(); for (IConfigurationListener cl : m_configuration.getConfigurationListeners()) { @@ -613,11 +601,7 @@ public void run() { try { XmlTest test = getTest(); - if (test.isJUnit()) { - privateRunJUnit(); - } else { - privateRun(test); - } + privateRun(test); } finally { afterRun(); forgetHeavyReferencesIfNeeded(); @@ -662,82 +646,6 @@ private void invokeTestConfigurations(ITestNGMethod[] testConfigurationMethods) } } - private ITestNGMethod[] m_allJunitTestMethods = new ITestNGMethod[] {}; - - private static final AtomicBoolean warnOnce = new AtomicBoolean(false); - - private void privateRunJUnit() { - if (warnOnce.compareAndSet(false, true)) { - String msg = - "Support to run JUnit tests using TestNG stands deprecated " - + "and will be removed in future versions. You can now use the JUnit5 TestNG " - + "engine to run both JUnit and TestNG tests. For more information refer to " - + "https://github.com/junit-team/testng-engine ."; - Logger.getLogger(TestRunner.class).warn(msg); - } - - final ClassInfoMap cim = new ClassInfoMap(m_testClassesFromXml, false); - final Set> classes = cim.getClasses(); - final List runMethods = Lists.newArrayList(); - List> workers = Lists.newArrayList(); - // FIXME: directly referencing JUnitTestRunner which uses JUnit classes - // may result in an class resolution exception under different JVMs - // The resolution process is not specified in the JVM spec with a specific implementation, - // so it can be eager => failure - workers.add( - new IWorker<>() { - /** @see TestMethodWorker#getTimeOut() */ - @Override - public long getTimeOut() { - return 0; - } - - /** @see java.lang.Runnable#run() */ - @Override - public void run() { - for (Class tc : classes) { - List includedMethods = cim.getXmlClass(tc).getIncludedMethods(); - List methods = Lists.newArrayList(); - for (XmlInclude inc : includedMethods) { - methods.add(inc.getName()); - } - IJUnitTestRunner tr = - IJUnitTestRunner.createTestRunner(m_objectFactory, TestRunner.this); - tr.setInvokedMethodListeners(m_invokedMethodListeners); - try { - tr.run(tc, methods.toArray(new String[0])); - } catch (Exception ex) { - LOGGER.error(ex.getMessage(), ex); - } finally { - runMethods.addAll(tr.getTestMethods()); - } - } - } - - @Override - public List getTasks() { - throw new TestNGException("JUnit not supported"); - } - - @Override - public int getPriority() { - if (m_allJunitTestMethods.length == 1) { - return m_allJunitTestMethods[0].getPriority(); - } else { - return 0; - } - } - - @Override - public int compareTo(@Nonnull IWorker other) { - return getPriority() - other.getPriority(); - } - }); - - runJUnitWorkers(workers); - m_allJunitTestMethods = runMethods.toArray(new ITestNGMethod[0]); - } - private static Comparator newComparator(boolean needPrioritySort) { return needPrioritySort ? new TestMethodComparator() : null; } @@ -890,14 +798,6 @@ public List> createWorkers(List methods) { .createWorkers(args); } - // - // Invoke the workers - // - private void runJUnitWorkers(List> workers) { - // Sequential run - workers.forEach(Runnable::run); - } - private void afterRun() { // invoke @AfterTest ITestNGMethod[] testConfigurationMethods = getAfterTestConfigurationMethods(); @@ -1039,10 +939,6 @@ public ISuite getSuite() { @Override public ITestNGMethod[] getAllTestMethods() { - if (getTest().isJUnit()) { - // This is true only when we are running JUnit mode - return m_allJunitTestMethods; - } return testMethodsContainer.getItems(); } diff --git a/testng-core/src/main/java/org/testng/internal/ClassImpl.java b/testng-core/src/main/java/org/testng/internal/ClassImpl.java index 287436f87c..233fff69c9 100644 --- a/testng-core/src/main/java/org/testng/internal/ClassImpl.java +++ b/testng-core/src/main/java/org/testng/internal/ClassImpl.java @@ -119,17 +119,6 @@ public Object[] getInstances(boolean create) { public Object[] getInstances(boolean create, String errorMsgPrefix) { Object[] result = {}; - if (m_testContext.getCurrentXmlTest().isJUnit()) { - if (create) { - DetailedAttributes ea = newDetailedAttributes(create, errorMsgPrefix); - CreationAttributes attributes = new CreationAttributes(m_testContext, null, ea); - result = - new Object[] { - Dispenser.newInstance(m_testContext.getSuite().getObjectFactory()) - .dispense(attributes) - }; - } - } if (m_instances.size() > 0) { result = m_instances.toArray(new Object[0]); } else { diff --git a/testng-core/src/main/java/org/testng/internal/Yaml.java b/testng-core/src/main/java/org/testng/internal/Yaml.java index 4001b1fa79..b373b1504b 100644 --- a/testng-core/src/main/java/org/testng/internal/Yaml.java +++ b/testng-core/src/main/java/org/testng/internal/Yaml.java @@ -1,6 +1,5 @@ package org.testng.internal; -import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; @@ -54,7 +53,7 @@ public static XmlSuite parse(String filePath, InputStream is, boolean loadClasse org.yaml.snakeyaml.Yaml y = new org.yaml.snakeyaml.Yaml(constructor); if (is == null) { - is = new FileInputStream(new File(filePath)); + is = new FileInputStream(filePath); } XmlSuite result = y.load(is); @@ -92,7 +91,6 @@ public static StringBuilder toYaml(XmlSuite suite) { StringBuilder result = new StringBuilder(); maybeAdd(result, "name", suite.getName(), null); - maybeAdd(result, "junit", suite.isJUnit(), XmlSuite.DEFAULT_JUNIT); maybeAdd(result, "verbose", suite.getVerbose(), XmlSuite.DEFAULT_VERBOSE); maybeAdd(result, "threadCount", suite.getThreadCount(), XmlSuite.DEFAULT_THREAD_COUNT); maybeAdd( @@ -145,7 +143,6 @@ private static void toYaml(StringBuilder result, XmlTest t) { String sp2 = " ".repeat(2); result.append(" ").append("- name: ").append(t.getName()).append("\n"); - maybeAdd(result, sp2, "junit", t.isJUnit(), XmlSuite.DEFAULT_JUNIT); maybeAdd(result, sp2, "verbose", t.getVerbose(), XmlSuite.DEFAULT_VERBOSE); maybeAdd(result, sp2, "timeOut", t.getTimeOut(), null); maybeAdd(result, sp2, "parallel", t.getParallel(), XmlSuite.DEFAULT_PARALLEL); @@ -180,7 +177,15 @@ private static void toYaml(StringBuilder result, XmlTest t) { result.append(sp2).append(sp2).append("xmlDependencyGroups:\n"); t.getXmlDependencyGroups() .forEach( - (k, v) -> result.append(sp2).append(sp2).append(sp2).append(k + ": " + v + "\n")); + (k, v) -> + result + .append(sp2) + .append(sp2) + .append(sp2) + .append(k) + .append(": ") + .append(v) + .append("\n")); } Map> mg = t.getMetaGroups(); diff --git a/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java b/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java deleted file mode 100644 index 0992166f47..0000000000 --- a/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.testng.junit; - -import java.util.Collection; -import java.util.List; -import org.testng.IInvokedMethodListener; -import org.testng.ITestNGMethod; -import org.testng.ITestObjectFactory; -import org.testng.TestNGException; -import org.testng.internal.ITestResultNotifier; -import org.testng.internal.Utils; - -/** - * An abstraction interface over JUnit test runners. - * - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public interface IJUnitTestRunner { - - void setInvokedMethodListeners(Collection listener); - - @Deprecated - default void setTestResultNotifier(ITestResultNotifier notifier) {} - - void run(Class junitTestClass, String... methods); - - List getTestMethods(); - - static IJUnitTestRunner createTestRunner( - ITestObjectFactory objectFactory, ITestResultNotifier runner) { - IJUnitTestRunner tr; - try { - // try to get runner for JUnit 4 first - Class.forName("org.junit.Test"); - tr = new JUnit4TestRunner(objectFactory, runner); - } catch (Throwable t) { - Utils.log( - IJUnitTestRunner.class.getSimpleName(), 2, "JUnit 4 was not found on the classpath"); - try { - // fallback to JUnit 3 - Class.forName("junit.framework.Test"); - tr = new JUnitTestRunner(objectFactory, runner); - } catch (Exception ex) { - Utils.log( - IJUnitTestRunner.class.getSimpleName(), 2, "JUnit 3 was not found on the classpath"); - // there's no JUnit on the classpath - throw new TestNGException("Cannot create JUnit runner", ex); - } - } - return tr; - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java deleted file mode 100644 index 9f8fd3b23f..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.testng.junit; - -import junit.framework.Test; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit3TestClass extends JUnitTestClass { - - public JUnit3TestClass(Test test) { - super(test.getClass()); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java deleted file mode 100644 index 1359fc29b8..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Method; -import junit.framework.Test; -import org.testng.ITestObjectFactory; -import org.testng.internal.ConstructorOrMethod; -import org.testng.internal.Utils; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit3TestMethod extends JUnitTestMethod { - - public JUnit3TestMethod(ITestObjectFactory objectFactory, JUnitTestClass owner, Test test) { - super(objectFactory, owner, getMethod(test), test); - } - - private static ConstructorOrMethod getMethod(Test t) { - String name = null; - try { - Method nameMethod = t.getClass().getMethod("getName"); - name = (String) nameMethod.invoke(t); - return new ConstructorOrMethod(t.getClass().getMethod(name)); - } catch (Throwable th) { - Utils.log( - "JUnit3TestMethod", - 2, - "Method '" + name + "' not found in class '" + t + "': " + th.getMessage()); - return null; - } - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java deleted file mode 100644 index 3d49301eae..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import junit.framework.Test; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit3TestRecognizer implements JUnitTestRecognizer { - - public JUnit3TestRecognizer() {} - - public boolean isTest(Class c) { - // class implementing junit.framework.Test with at least one test* method - if (Test.class.isAssignableFrom(c)) { - boolean haveTest = false; - for (Method m : c.getMethods()) { - if (m.getName().startsWith("test")) { - haveTest = true; - break; - } - } - if (haveTest) { - return true; - } - } - try { - // or a class with public static Test suite() method - Method m = c.getDeclaredMethod("suite"); - if (Modifier.isPublic(m.getModifiers()) && Modifier.isStatic(m.getModifiers())) { - return m.getReturnType().isAssignableFrom(Test.class); - } - } catch (Throwable t) { - return false; - } - return false; - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java deleted file mode 100644 index 136934869a..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Method; -import org.testng.internal.ConstructorOrMethod; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit4ConfigurationMethod extends ConstructorOrMethod { - - private final Class declaringClass; - - public JUnit4ConfigurationMethod(Class declaringClass) { - super((Method) null); - this.declaringClass = declaringClass; - } - - @Override - public Class getDeclaringClass() { - return declaringClass; - } - - @Override - public String getName() { - return "Configuration method from '" + declaringClass.getName() + "'"; - } - - @Override - public String toString() { - return getName(); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4SpockMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit4SpockMethod.java deleted file mode 100644 index 74b62adb30..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4SpockMethod.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Method; -import org.junit.runner.Description; -import org.testng.internal.ConstructorOrMethod; - -/** @deprecated - Support for Spock1.x series is being deprecated as of TestNG 7.7.0 */ -@Deprecated -public class JUnit4SpockMethod extends ConstructorOrMethod { - - private static final Class SPOCK_SPEC_CLASS = getSpockSpecClass(); - - private static Class getSpockSpecClass() { - try { - return Class.forName("spock.lang.Specification"); - } catch (ClassNotFoundException e) { - return null; - } - } - - public static boolean isSpockClass(Class testClass) { - return JUnit4SpockMethod.SPOCK_SPEC_CLASS != null - && JUnit4SpockMethod.SPOCK_SPEC_CLASS.isAssignableFrom(testClass); - } - - private final Class declaringClass; - private final String description; - - public JUnit4SpockMethod(Description description) { - super((Method) null); - this.declaringClass = description.getTestClass(); - this.description = description.getDisplayName(); - } - - @Override - public Class getDeclaringClass() { - return declaringClass; - } - - @Override - public String getName() { - return description; - } - - @Override - public String toString() { - return getName(); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java deleted file mode 100644 index d719763bad..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.testng.junit; - -import org.junit.runner.Description; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit4TestClass extends JUnitTestClass { - - public JUnit4TestClass(Description test) { - super(descriptionToClass(test)); - } - - private static Class descriptionToClass(Description test) { - Class result = test.getTestClass(); - if (result == null) { - result = org.testng.internal.ClassHelper.forName(test.getClassName()); - } - return result; - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java deleted file mode 100644 index 7a7d6d7200..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.testng.junit; - -import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.runner.Description; -import org.testng.ITestObjectFactory; -import org.testng.internal.ConstructorOrMethod; -import org.testng.internal.Utils; -import org.testng.log4testng.Logger; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit4TestMethod extends JUnitTestMethod { - - private static final AtomicBoolean warnOnce = new AtomicBoolean(false); - - public JUnit4TestMethod( - ITestObjectFactory objectFactory, JUnitTestClass owner, Description desc) { - super(objectFactory, owner, desc.getMethodName(), getMethod(owner.getRealClass(), desc), desc); - } - - private static ConstructorOrMethod getMethod(Class c, Description desc) { - String method = desc.getMethodName(); - if (JUnit4SpockMethod.isSpockClass(c)) { - if (warnOnce.compareAndSet(false, true)) { - String msg = - "Support for running Spock 1.x series is being deprecated and will " - + "be removed in the upcoming versions of TestNG. Spock 2.x based tests use " - + "the JUnit5 engine for running them. " - + "To run both TestNG and Spock2.x tests using JUnit5 refer to " - + "https://github.com/junit-team/testng-engine"; - Logger.getLogger(JUnit4TestMethod.class).warn(msg); - } - return new JUnit4SpockMethod(desc); - } - if (method == null) { - return new JUnit4ConfigurationMethod(c); - } - // remove [index] from method name in case of parameterized test - int idx = method.indexOf('['); - if (idx != -1) { - method = method.substring(0, idx); - } - try { - return new ConstructorOrMethod(c.getMethod(method)); - } catch (Throwable t) { - Utils.log( - "JUnit4TestMethod", - 2, - "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage()); - return null; - } - } - - @Override - public boolean isTest() { - return !(m_method instanceof JUnit4ConfigurationMethod); - } - - @Override - public String toString() { - return m_method.toString(); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java deleted file mode 100644 index 2b238466c0..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.testng.junit; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import org.junit.runner.RunWith; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public final class JUnit4TestRecognizer implements JUnitTestRecognizer { - - public JUnit4TestRecognizer() {} - - public boolean isTest(Class c) { - for (Annotation an : c.getAnnotations()) { - if (RunWith.class.isAssignableFrom(an.annotationType())) { - return true; - } - } - boolean haveTest = false; - for (Method m : c.getMethods()) { - for (Annotation a : m.getDeclaredAnnotations()) { - if (org.junit.Test.class.isAssignableFrom(a.annotationType())) { - haveTest = true; - break; - } - } - } - return haveTest; - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java deleted file mode 100644 index 2b7a938960..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java +++ /dev/null @@ -1,272 +0,0 @@ -package org.testng.junit; - -import java.util.*; -import java.util.regex.Pattern; -import org.junit.runner.Description; -import org.junit.runner.JUnitCore; -import org.junit.runner.Request; -import org.junit.runner.Result; -import org.junit.runner.manipulation.Filter; -import org.junit.runner.notification.Failure; -import org.junit.runner.notification.RunListener; -import org.testng.*; -import org.testng.collections.Lists; -import org.testng.internal.ITestResultNotifier; -import org.testng.internal.TestResult; -import org.testng.internal.invokers.IInvocationStatus; -import org.testng.internal.invokers.InvokedMethod; - -/** - * A JUnit TestRunner that records/triggers all information/events necessary to TestNG. - * - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnit4TestRunner implements IJUnitTestRunner { - - private final ITestObjectFactory objectFactory; - private final ITestResultNotifier m_parentRunner; - private final List m_listeners; - private final List m_methods = Lists.newArrayList(); - private Collection m_invokeListeners = Lists.newArrayList(); - private final Map m_foundMethods = new WeakHashMap<>(); - private final ITestListener m_exitCodeListener; - - public JUnit4TestRunner(ITestObjectFactory objectFactory, ITestResultNotifier tr) { - this.objectFactory = objectFactory; - m_parentRunner = tr; - m_listeners = m_parentRunner.getTestListeners(); - m_exitCodeListener = m_parentRunner.getExitCodeListener(); - } - - /** - * Needed from TestRunner in order to figure out what JUnit test methods were run. - * - * @return the list of all JUnit test methods run - */ - @Override - public List getTestMethods() { - return m_methods; - } - - public void setInvokedMethodListeners(Collection listeners) { - m_invokeListeners = listeners; - } - - /** - * A start implementation that ignores the TestResult - * - * @param testClass the JUnit test class - */ - @Override - public void run(Class testClass, String... methods) { - start(testClass, methods); - } - - /** - * Starts a test run. Analyzes the command line arguments and runs the given test suite. - * - * @param testCase The test class - * @param methods The test methods - * @return The result - */ - public Result start(final Class testCase, final String... methods) { - try { - JUnitCore core = new JUnitCore(); - core.addListener(new RL()); - Request r = Request.aClass(testCase); - return core.run( - r.filterWith( - new Filter() { - - @Override - public boolean shouldRun(Description description) { - if (description == null) { - return false; - } - if (methods.length == 0) { - if (description.getTestClass() != null) { - ITestResult tr = createTestResult(objectFactory, description); - m_foundMethods.put(description, tr); - } - // run everything - return true; - } - for (String m : methods) { - Pattern p = Pattern.compile(m); - if (p.matcher(description.getMethodName()).matches()) { - ITestResult tr = createTestResult(objectFactory, description); - m_foundMethods.put(description, tr); - return true; - } - } - return false; - } - - @Override - public String describe() { - return "TestNG method filter"; - } - })); - } catch (Throwable t) { - throw new TestNGException("Failure in JUnit mode for class " + testCase.getName(), t); - } - } - - private class RL extends RunListener { - - private List notified = new LinkedList<>(); - - @Override - public void testAssumptionFailure(Failure failure) { - notified.add(failure.getDescription()); - ITestResult tr = m_foundMethods.get(failure.getDescription()); - validate(tr, failure.getDescription()); - runAfterInvocationListeners(tr); - tr.setStatus(TestResult.SKIP); - tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); - tr.setThrowable(failure.getException()); - m_parentRunner.addSkippedTest(tr.getMethod(), tr); - for (ITestListener l : m_listeners) { - l.onTestSkipped(tr); - } - m_exitCodeListener.onTestSkipped(tr); - } - - @Override - public void testFailure(Failure failure) throws Exception { - if (failure == null) { - return; - } - if (isAssumptionFailed(failure)) { - this.testAssumptionFailure(failure); - return; - } - notified.add(failure.getDescription()); - ITestResult tr = m_foundMethods.get(failure.getDescription()); - if (tr == null) { - // Not a test method, should be a config - tr = createTestResult(objectFactory, failure.getDescription()); - runAfterInvocationListeners(tr); - tr.setStatus(TestResult.FAILURE); - tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); - tr.setThrowable(failure.getException()); - for (IConfigurationListener l : m_parentRunner.getConfigurationListeners()) { - l.onConfigurationFailure(tr); - } - for (Description childDesc : failure.getDescription().getChildren()) { - testIgnored(childDesc); - } - } else { - runAfterInvocationListeners(tr); - tr.setStatus(TestResult.FAILURE); - tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); - tr.setThrowable(failure.getException()); - m_parentRunner.addFailedTest(tr.getMethod(), tr); - for (ITestListener l : m_listeners) { - l.onTestFailure(tr); - } - m_exitCodeListener.onTestFailure(tr); - } - } - - @Override - public void testFinished(Description description) throws Exception { - ITestResult tr = m_foundMethods.get(description); - validate(tr, description); - runAfterInvocationListeners(tr); - if (!notified.contains(description)) { - tr.setStatus(TestResult.SUCCESS); - tr.setEndMillis(Calendar.getInstance().getTimeInMillis()); - m_parentRunner.addPassedTest(tr.getMethod(), tr); - for (ITestListener l : m_listeners) { - l.onTestSuccess(tr); - } - m_exitCodeListener.onTestSuccess(tr); - } - m_methods.add(tr.getMethod()); - } - - @Override - public void testIgnored(Description description) throws Exception { - if (!notified.contains(description)) { - notified.add(description); - ITestResult tr = m_foundMethods.get(description); - validate(tr, description); - runAfterInvocationListeners(tr); - tr.setStatus(TestResult.SKIP); - tr.setEndMillis(tr.getStartMillis()); - m_parentRunner.addSkippedTest(tr.getMethod(), tr); - m_methods.add(tr.getMethod()); - for (ITestListener l : m_listeners) { - l.onTestSkipped(tr); - } - m_exitCodeListener.onTestSkipped(tr); - } - } - - @Override - public void testRunFinished(Result result) throws Exception {} - - @Override - public void testRunStarted(Description description) throws Exception {} - - @Override - public void testStarted(Description description) throws Exception { - ITestResult tr = m_foundMethods.get(description); - validate(tr, description); - for (ITestListener l : m_listeners) { - l.onTestStart(tr); - } - m_exitCodeListener.onTestStart(tr); - } - - private void runAfterInvocationListeners(ITestResult tr) { - InvokedMethod im = new InvokedMethod(tr.getEndMillis(), tr); - for (IInvokedMethodListener l : m_invokeListeners) { - l.afterInvocation(im, tr); - } - } - - private void validate(ITestResult tr, Description description) { - if (tr == null) { - throw new TestNGException(stringify(description)); - } - } - - private String stringify(Description description) { - return description.getClassName() + "." + description.getMethodName() + "()"; - } - } - - private ITestResult createTestResult(ITestObjectFactory objectFactory, Description test) { - JUnit4TestClass tc = new JUnit4TestClass(test); - JUnitTestMethod tm = new JUnit4TestMethod(objectFactory, tc, test); - - ITestContext ctx = null; - if (m_parentRunner instanceof ITestContext) { - ctx = (ITestContext) m_parentRunner; - } - TestResult tr = TestResult.newContextAwareTestResult(tm, ctx); - - InvokedMethod im = new InvokedMethod(tr.getStartMillis(), tr); - if (tr.getMethod() instanceof IInvocationStatus) { - ((IInvocationStatus) tr.getMethod()).setInvokedAt(im.getDate()); - } - for (IInvokedMethodListener l : m_invokeListeners) { - l.beforeInvocation(im, tr); - } - return tr; - } - - private static boolean isAssumptionFailed(Failure failure) { - //noinspection ThrowableResultOfMethodCallIgnored - final Throwable exception = failure.getException(); - //noinspection SimplifiableIfStatement - if (exception == null) { - return false; - } - return "org.junit.internal.AssumptionViolatedException" - .equals(exception.getClass().getCanonicalName()); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java b/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java deleted file mode 100644 index 32ef20ffbe..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Method; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.testng.ITestMethodFinder; -import org.testng.ITestNGMethod; -import org.testng.ITestObjectFactory; -import org.testng.collections.Lists; -import org.testng.internal.ConstructorOrMethod; -import org.testng.internal.TestNGMethod; -import org.testng.internal.annotations.IAnnotationFinder; -import org.testng.internal.reflect.ReflectionHelper; -import org.testng.xml.XmlTest; - -/** - * This class locates all test and configuration methods according to JUnit. It is used to change - * the strategy used by TestRunner to locate its test methods. - * - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnitMethodFinder implements ITestMethodFinder { - - private final ITestObjectFactory objectFactory; - private final IAnnotationFinder m_annotationFinder; - - public JUnitMethodFinder(ITestObjectFactory objectFactory, IAnnotationFinder finder) { - this.objectFactory = objectFactory; - m_annotationFinder = finder; - } - - @Override - public ITestNGMethod[] getTestMethods(Class cls, XmlTest xmlTest) { - - return privateFindTestMethods( - method -> method.getName().startsWith("test") && method.getParameterTypes().length == 0, - cls); - } - - private ITestNGMethod[] privateFindTestMethods(INameFilter filter, Class cls) { - List vResult = Lists.newArrayList(); - - // We do not want to walk up the class hierarchy and accept the - // same method twice (e.g. setUp) which would lead to double-invocation. - // All relevant JUnit methods are parameter-less so we store accepted - // method names in a Set to filter out duplicates. - Set acceptedMethodNames = new HashSet<>(); - - // - // Collect all methods that start with test - // - Class current = cls; - while (!(current == Object.class)) { - Method[] allMethods = ReflectionHelper.excludingMain(current); - for (Method allMethod : allMethods) { - ITestNGMethod m = - new TestNGMethod(objectFactory, allMethod, m_annotationFinder, null, null); - ConstructorOrMethod method = m.getConstructorOrMethod(); - String methodName = method.getName(); - if (filter.accept(method) && !acceptedMethodNames.contains(methodName)) { - vResult.add(m); - acceptedMethodNames.add(methodName); - } - } - current = current.getSuperclass(); - } - - return vResult.toArray(new ITestNGMethod[0]); - } - - @Override - public ITestNGMethod[] getBeforeTestMethods(Class cls) { - return privateFindTestMethods(method -> "setUp".equals(method.getName()), cls); - } - - @Override - public ITestNGMethod[] getAfterTestMethods(Class cls) { - return privateFindTestMethods(method -> "tearDown".equals(method.getName()), cls); - } - - @Override - public ITestNGMethod[] getAfterClassMethods(Class cls) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getBeforeClassMethods(Class cls) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getBeforeSuiteMethods(Class cls) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getAfterSuiteMethods(Class cls) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getBeforeTestConfigurationMethods(Class testClass) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getAfterTestConfigurationMethods(Class testClass) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getBeforeGroupsConfigurationMethods(Class testClass) { - return new ITestNGMethod[0]; - } - - @Override - public ITestNGMethod[] getAfterGroupsConfigurationMethods(Class testClass) { - return new ITestNGMethod[0]; - } -} -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -interface INameFilter { - boolean accept(ConstructorOrMethod method); -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestClass.java b/testng-core/src/main/java/org/testng/junit/JUnitTestClass.java deleted file mode 100644 index 38918ae1b5..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestClass.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.testng.junit; - -import java.util.List; -import org.testng.ITestClass; -import org.testng.ITestNGMethod; -import org.testng.collections.Lists; -import org.testng.xml.XmlClass; -import org.testng.xml.XmlTest; - -// NO JUnit specific code here to avoid runtime errors -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public abstract class JUnitTestClass implements ITestClass { - - private List m_testMethods = Lists.newArrayList(); - private List m_beforeClass = Lists.newArrayList(); - private List m_afterClass = Lists.newArrayList(); - private List m_beforeTest = Lists.newArrayList(); - private List m_afterTest = Lists.newArrayList(); - private final Class m_realClass; - private final Object[] m_instances; - private final long[] m_instanceHashes; - - public JUnitTestClass(Class test) { - m_realClass = test; - m_instances = new Object[] {test}; - m_instanceHashes = new long[] {test.hashCode()}; - } - - List getTestMethodList() { - return m_testMethods; - } - - /** @see org.testng.IClass#addInstance(java.lang.Object) */ - @Override - public void addInstance(Object instance) { - throw new IllegalStateException("addInstance is not supported for JUnit"); - } - - /** @see org.testng.IClass#getName() */ - @Override - public String getName() { - return m_realClass.getName(); - } - - /** @see org.testng.IClass#getRealClass() */ - @Override - public Class getRealClass() { - return m_realClass; - } - - @Override - public String getTestName() { - return null; - } - - @Override - public XmlTest getXmlTest() { - return null; - } - - @Override - public XmlClass getXmlClass() { - return null; - } - - /** @see org.testng.ITestClass#getInstanceHashCodes() */ - @Override - public long[] getInstanceHashCodes() { - return m_instanceHashes; - } - - /** @see org.testng.ITestClass#getInstances(boolean) */ - @Override - public Object[] getInstances(boolean reuse) { - return m_instances; - } - - /** @see org.testng.ITestClass#getTestMethods() */ - @Override - public ITestNGMethod[] getTestMethods() { - return m_testMethods.toArray(new ITestNGMethod[m_testMethods.size()]); - } - - /** @see org.testng.ITestClass#getBeforeTestMethods() */ - @Override - public ITestNGMethod[] getBeforeTestMethods() { - return m_beforeTest.toArray(new ITestNGMethod[m_beforeTest.size()]); - } - - /** @see org.testng.ITestClass#getAfterTestMethods() */ - @Override - public ITestNGMethod[] getAfterTestMethods() { - return m_afterTest.toArray(new ITestNGMethod[m_afterTest.size()]); - } - - /** @see org.testng.ITestClass#getBeforeClassMethods() */ - @Override - public ITestNGMethod[] getBeforeClassMethods() { - return m_beforeClass.toArray(new ITestNGMethod[m_beforeClass.size()]); - } - - /** @see org.testng.ITestClass#getAfterClassMethods() */ - @Override - public ITestNGMethod[] getAfterClassMethods() { - return m_afterClass.toArray(new ITestNGMethod[m_afterClass.size()]); - } - - // features not supported by JUnit - private static final ITestNGMethod[] EMPTY_METHODARRAY = new ITestNGMethod[0]; - - /** @see org.testng.ITestClass#getBeforeSuiteMethods() */ - @Override - public ITestNGMethod[] getBeforeSuiteMethods() { - return EMPTY_METHODARRAY; - } - - /** @see org.testng.ITestClass#getAfterSuiteMethods() */ - @Override - public ITestNGMethod[] getAfterSuiteMethods() { - return EMPTY_METHODARRAY; - } - - /** @see org.testng.ITestClass#getBeforeGroupsMethods() */ - @Override - public ITestNGMethod[] getBeforeGroupsMethods() { - return EMPTY_METHODARRAY; - } - - /** @see org.testng.ITestClass#getAfterGroupsMethods() */ - @Override - public ITestNGMethod[] getAfterGroupsMethods() { - return EMPTY_METHODARRAY; - } - - // already deprecated stuff, not usable in junit - /** @see org.testng.ITestClass#getBeforeTestConfigurationMethods() */ - @Override - public ITestNGMethod[] getBeforeTestConfigurationMethods() { - return EMPTY_METHODARRAY; - } - - /** @see org.testng.ITestClass#getAfterTestConfigurationMethods() */ - @Override - public ITestNGMethod[] getAfterTestConfigurationMethods() { - return EMPTY_METHODARRAY; - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java b/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java deleted file mode 100644 index 4e195a3a4a..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Modifier; -import org.testng.internal.Utils; -import org.testng.internal.objects.InstanceCreator; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public final class JUnitTestFinder { - - private static final String JUNIT3_TEST = "junit.framework.Test"; - private static final String JUNIT3_FINDER = "org.testng.junit.JUnit3TestRecognizer"; - private static final String JUNIT4_TEST = "org.junit.Test"; - private static final String JUNIT4_FINDER = "org.testng.junit.JUnit4TestRecognizer"; - private static final JUnitTestRecognizer junit3; - private static final JUnitTestRecognizer junit4; - - static { - junit3 = getJUnitTestRecognizer(JUNIT3_TEST, JUNIT3_FINDER); - junit4 = getJUnitTestRecognizer(JUNIT4_TEST, JUNIT4_FINDER); - if (junit3 == null) { - Utils.log("JUnitTestFinder", 2, "JUnit3 was not found on the classpath"); - } - if (junit4 == null) { - Utils.log("JUnitTestFinder", 2, "JUnit4 was not found on the classpath"); - } - } - - public static boolean isJUnitTest(Class c) { - if (!haveJUnit()) { - return false; - } - // only public classes are interesting, so filter out the rest - if (!Modifier.isPublic(c.getModifiers()) || c.isInterface() || c.isAnnotation() || c.isEnum()) { - return false; - } - return (junit3 != null && junit3.isTest(c)) || (junit4 != null && junit4.isTest(c)); - } - - private static boolean haveJUnit() { - return junit3 != null || junit4 != null; - } - - private static JUnitTestRecognizer getJUnitTestRecognizer(String test, String name) { - try { - Class.forName(test); - return InstanceCreator.newInstance(name); - } catch (Throwable t) { - // ignore - return null; - } - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java deleted file mode 100644 index d4286fa9eb..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.testng.junit; - -import org.testng.ITestNGMethod; -import org.testng.ITestObjectFactory; -import org.testng.internal.BaseTestMethod; -import org.testng.internal.ConstructorOrMethod; - -// NO JUnit specific code here to avoid runtime errors -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public abstract class JUnitTestMethod extends BaseTestMethod { - - protected JUnitTestMethod( - ITestObjectFactory objectFactory, - JUnitTestClass owner, - ConstructorOrMethod method, - Object instance) { - this(objectFactory, owner, method.getName(), method, instance); - } - - protected JUnitTestMethod( - ITestObjectFactory objectFactory, - JUnitTestClass owner, - String methodName, - ConstructorOrMethod method, - Object instance) { - super(objectFactory, methodName, method, null, instance); - setTestClass(owner); - owner.getTestMethodList().add(this); - } - - @Override - public boolean isTest() { - return true; - } - - @Override - public ITestNGMethod clone() { - throw new IllegalStateException("clone is not supported for JUnit"); - } -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java deleted file mode 100644 index 486a0e1f76..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.testng.junit; - -/** - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -interface JUnitTestRecognizer { - - boolean isTest(Class c); -} diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java b/testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java deleted file mode 100644 index 69756dcb41..0000000000 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java +++ /dev/null @@ -1,269 +0,0 @@ -package org.testng.junit; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Calendar; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; -import junit.framework.AssertionFailedError; -import junit.framework.Test; -import junit.framework.TestListener; -import junit.framework.TestResult; -import junit.framework.TestSuite; -import org.testng.*; -import org.testng.collections.Lists; -import org.testng.internal.ITestResultNotifier; -import org.testng.internal.ListenerOrderDeterminer; -import org.testng.internal.TestListenerHelper; -import org.testng.internal.invokers.InvokedMethod; - -/** - * A JUnit TestRunner that records/triggers all information/events necessary to TestNG. - * - * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.7.0 - */ -@Deprecated -public class JUnitTestRunner implements TestListener, IJUnitTestRunner { - public static final String SUITE_METHODNAME = "suite"; - - private final ITestObjectFactory m_objectFactory; - private final ITestResultNotifier m_parentRunner; - - private final Map m_tests = new WeakHashMap<>(); - private final List m_methods = Lists.newArrayList(); - private Collection m_invokedMethodListeners = Lists.newArrayList(); - - public JUnitTestRunner(ITestObjectFactory objectFactory, ITestResultNotifier tr) { - m_objectFactory = objectFactory; - m_parentRunner = tr; - } - - /** - * Needed from TestRunner in order to figure out what JUnit test methods were run. - * - * @return the list of all JUnit test methods run - */ - @Override - public List getTestMethods() { - return m_methods; - } - - /** @see junit.framework.TestListener#startTest(junit.framework.Test) */ - @Override - public void startTest(Test test) { - m_tests.put(test, new TestRunInfo(Calendar.getInstance().getTimeInMillis())); - } - - /** @see junit.framework.TestListener#addError(junit.framework.Test, java.lang.Throwable) */ - @Override - public void addError(Test test, Throwable t) { - recordFailure(test, t); - } - - /** - * @see junit.framework.TestListener#addFailure(junit.framework.Test, - * junit.framework.AssertionFailedError) - */ - @Override - public void addFailure(Test test, AssertionFailedError t) { - recordFailure(test, t); - } - - private void recordFailure(Test test, Throwable t) { - TestRunInfo tri = m_tests.get(test); - if (null != tri) { - tri.setThrowable(t); - } - } - - /** @see junit.framework.TestListener#endTest(junit.framework.Test) */ - @Override - public void endTest(Test test) { - TestRunInfo tri = m_tests.get(test); - if (null == tri) { - return; // HINT: this should never happen. How do I protect myself? - } - - org.testng.internal.TestResult tr = recordResults(test, tri); - // For onTestStart method, still run as insert order - // but regarding - // onTestSkipped/onTestFailedButWithinSuccessPercentage/onTestFailedWithTimeout/onTestFailure/onTestSuccess, it should be reverse order. - boolean isFinished = tr.getStatus() != ITestResult.STARTED; - List listeners = - isFinished - ? ListenerOrderDeterminer.reversedOrder(m_parentRunner.getTestListeners()) - : ListenerOrderDeterminer.order(m_parentRunner.getTestListeners()); - TestListenerHelper.runTestListeners(tr, listeners); - } - - public void setInvokedMethodListeners(Collection listeners) { - m_invokedMethodListeners = listeners; - } - - private org.testng.internal.TestResult recordResults(Test test, TestRunInfo tri) { - JUnitTestClass tc = new JUnit3TestClass(test); - JUnitTestMethod tm = new JUnit3TestMethod(m_objectFactory, tc, test); - - ITestContext ctx = null; - if (m_parentRunner instanceof ITestContext) { - ctx = (ITestContext) m_parentRunner; - } - - org.testng.internal.TestResult tr = - org.testng.internal.TestResult.newEndTimeAwareTestResult( - tm, ctx, tri.m_failure, tri.m_start); - - if (tri.isFailure()) { - tr.setStatus(ITestResult.FAILURE); - m_parentRunner.addFailedTest(tm, tr); - } else { - m_parentRunner.addPassedTest(tm, tr); - } - - InvokedMethod im = new InvokedMethod(tri.m_start, tr); - tm.setInvokedAt(im.getDate()); - m_methods.add(tm); - for (IInvokedMethodListener l : m_invokedMethodListeners) { - l.beforeInvocation(im, tr); - } - - return tr; - } - - /** - * Returns the Test corresponding to the given suite. This is a template method, subclasses - * override runFailed(), clearStatus(). - * - * @param testClass The test class - * @param methods The test methods - * @return The corresponding Test - */ - protected Test getTest(Class testClass, String... methods) { - if (methods.length > 0) { - TestSuite ts = new TestSuite(); - try { - Constructor c = testClass.getConstructor(String.class); - for (String m : methods) { - try { - ts.addTest(m_objectFactory.newInstance(c, m)); - } catch (TestNGException ex) { - runFailed(testClass, ex.getMessage()); - } catch (IllegalArgumentException ex) { - runFailed(testClass, "actual and formal parameters differ " + ex); - } - } - } catch (NoSuchMethodException ex) { - runFailed(testClass, "no constructor accepting String argument found " + ex); - } catch (SecurityException ex) { - runFailed(testClass, "security exception " + ex); - } - return ts; - } - Method suiteMethod = null; - try { - suiteMethod = testClass.getMethod(SUITE_METHODNAME, new Class[0]); - } catch (Exception e) { - - // try to extract a test suite automatically - return new TestSuite(testClass); - } - if (!Modifier.isStatic(suiteMethod.getModifiers())) { - runFailed(testClass, "suite() method must be static"); - - return null; - } - Test test = null; - try { - test = (Test) suiteMethod.invoke(null, (Object[]) new Class[0]); // static method - if (test == null) { - return test; - } - } catch (InvocationTargetException e) { - runFailed(testClass, "failed to invoke method suite():" + e.getTargetException().toString()); - - return null; - } catch (IllegalAccessException e) { - runFailed(testClass, "failed to invoke method suite():" + e.toString()); - - return null; - } - - return test; - } - - /** - * A start implementation that ignores the TestResult - * - * @param testClass the JUnit test class - */ - @Override - public void run(Class testClass, String... methods) { - start(testClass, methods); - } - - /** - * Starts a test run. Analyzes the command line arguments and runs the given test suite. - * - * @param testCase The test class to run - * @param methods The test methods to run - * @return The test result - */ - public TestResult start(Class testCase, String... methods) { - try { - Test suite = getTest(testCase, methods); - - if (null != suite) { - return doRun(suite); - } else { - runFailed(testCase, "could not create/run JUnit test suite"); - } - } catch (Exception e) { - runFailed(testCase, "could not create/run JUnit test suite: " + e.getMessage()); - } - - return null; - } - - protected void runFailed(Class clazz, String message) { - throw new TestNGException( - "Failure in JUnit mode for class " + clazz.getName() + ": " + message); - } - - /** - * Creates the TestResult to be used for the test run. - * - * @return The created test result - */ - protected TestResult createTestResult() { - return new TestResult(); - } - - protected TestResult doRun(Test suite) { - TestResult result = createTestResult(); - result.addListener(this); - suite.run(result); - - return result; - } - - private static class TestRunInfo { - private final long m_start; - private Throwable m_failure; - - public TestRunInfo(long start) { - m_start = start; - } - - public boolean isFailure() { - return null != m_failure; - } - - public void setThrowable(Throwable t) { - m_failure = t; - } - } -} diff --git a/testng-core/src/main/java/org/testng/reporters/FailedReporter.java b/testng-core/src/main/java/org/testng/reporters/FailedReporter.java index 155bf60caf..58d6164544 100644 --- a/testng-core/src/main/java/org/testng/reporters/FailedReporter.java +++ b/testng-core/src/main/java/org/testng/reporters/FailedReporter.java @@ -210,7 +210,6 @@ private void createXmlTest( xmlTest.setExcludedGroups(srcXmlTest.getExcludedGroups()); xmlTest.setParallel(srcXmlTest.getParallel()); xmlTest.setParameters(srcXmlTest.getLocalParameters()); - xmlTest.setJUnit(srcXmlTest.isJUnit()); List xmlClasses = createXmlClasses(methods, srcXmlTest); xmlTest.setXmlClasses(xmlClasses); } diff --git a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java index c926b797aa..907257bb1f 100644 --- a/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java +++ b/testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java @@ -5,7 +5,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; @@ -160,7 +159,7 @@ private static boolean skipConsideringSystemId(String systemId) { private static boolean isMalformedFileSystemBasedSystemId(String systemId) { try { - URL url = new URL(URLDecoder.decode(systemId, StandardCharsets.UTF_8.name()).trim()); + URL url = new URL(URLDecoder.decode(systemId, StandardCharsets.UTF_8).trim()); if (url.getProtocol().equals("file")) { File file = new File(url.getFile()); boolean isDirectory = file.isDirectory(); @@ -168,7 +167,7 @@ private static boolean isMalformedFileSystemBasedSystemId(String systemId) { return isDirectory || !fileExists; } return false; - } catch (MalformedURLException | UnsupportedEncodingException e) { + } catch (MalformedURLException e) { return true; } } @@ -225,7 +224,7 @@ private void xmlSuite(boolean start, Attributes attributes) { } String jUnit = attributes.getValue("junit"); if (null != jUnit) { - m_currentSuite.setJUnit(Boolean.valueOf(jUnit)); + warnSinceJUnitDetected(); } String parallel = attributes.getValue("parallel"); if (parallel != null) { @@ -364,7 +363,7 @@ private void xmlTest(boolean start, Attributes attributes) { } String jUnit = attributes.getValue("junit"); if (null != jUnit) { - m_currentTest.setJUnit(Boolean.parseBoolean(jUnit)); + warnSinceJUnitDetected(); } String skip = attributes.getValue("skipfailedinvocationcounts"); if (skip != null) { @@ -843,4 +842,14 @@ private static String expandValue(String value) { return value; } } + + private static void warnSinceJUnitDetected() { + String msg = + "Ability to run JUnit tests via TestNG was deprecated in v7.7.0 and is NOW being removed permanently." + + " If you would like to run a mixture of TestNG and JUnit tests then please take a look at " + + " https://github.com/junit-team/testng-engine which is now maintained by the JUnit team"; + // Intentionally logging this to the error console so that it's visible to the user. + System.err.println(msg); + ; + } } diff --git a/testng-core/src/test/groovy/test/groovy/EasyJUnitGroovySample.groovy b/testng-core/src/test/groovy/test/groovy/EasyJUnitGroovySample.groovy deleted file mode 100644 index fe7c501671..0000000000 --- a/testng-core/src/test/groovy/test/groovy/EasyJUnitGroovySample.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package test.groovy - -import org.junit.Test - -import static groovy.test.GroovyAssert.shouldFail - -// Sample from https://groovy-lang.org/testing.html#_junit_4 -class EasyJUnitGroovySample { - - @Test - void indexOutOfBoundsAccess() { - def numbers = [1, 2, 3, 4] - shouldFail { - numbers.get(4) - } - } -} diff --git a/testng-core/src/test/groovy/test/groovy/GroovyTest.groovy b/testng-core/src/test/groovy/test/groovy/GroovyTest.groovy index e567b0da2d..b67ff96fcd 100644 --- a/testng-core/src/test/groovy/test/groovy/GroovyTest.groovy +++ b/testng-core/src/test/groovy/test/groovy/GroovyTest.groovy @@ -13,32 +13,6 @@ import static org.assertj.core.api.Assertions.assertThat class GroovyTest extends SimpleBaseTest { - @Test - void easyGroovySampleShouldWork() { - def tng = create(EasyJUnitGroovySample) - tng.setJUnit(true) - def adapter = new TestListenerAdapter() - tng.addListener((ITestNGListener)adapter) - tng.run() - - assert adapter.failedTests.isEmpty() - assert adapter.skippedTests.isEmpty() - assert adapter.passedTests.size() == 1 - } - - @Test - void specialNameGroovySampleShouldWork() { - def tng = create(SpecialNameJUnitGroovySample) - tng.setJUnit(true) - def adapter = new TestListenerAdapter() - tng.addListener((ITestNGListener)adapter) - tng.run() - - assert adapter.failedTests.isEmpty() - assert adapter.skippedTests.isEmpty() - assert adapter.passedTests.size() == 1 - } - @Test(description = "GITHUB-2360") void groovyInternalMethodsAreSkipped() { def tng = create Issue2360Sample diff --git a/testng-core/src/test/groovy/test/groovy/SpecialNameJUnitGroovySample.groovy b/testng-core/src/test/groovy/test/groovy/SpecialNameJUnitGroovySample.groovy deleted file mode 100644 index 1f56fc4316..0000000000 --- a/testng-core/src/test/groovy/test/groovy/SpecialNameJUnitGroovySample.groovy +++ /dev/null @@ -1,17 +0,0 @@ -package test.groovy - -import org.junit.Test - -import static groovy.test.GroovyAssert.shouldFail - -// Sample from https://groovy-lang.org/testing.html#_junit_4 -class SpecialNameJUnitGroovySample { - - @Test - void "index Out Of Bounds Access"() { - def numbers = [1, 2, 3, 4] - shouldFail { - numbers.get(4) - } - } -} diff --git a/testng-core/src/test/java/ConverterSample2.java b/testng-core/src/test/java/ConverterSample2.java deleted file mode 100644 index ed9c31c61b..0000000000 --- a/testng-core/src/test/java/ConverterSample2.java +++ /dev/null @@ -1,24 +0,0 @@ -// Not that this file has no package (that's what we are testing) and therefore, -// it is at the wrong location, but it's easier to leave it here. -// Also, do not change the line numbers since the test will make sure -// that the tags are generated in hardcoded line numbers - -import junit.framework.TestCase; - -public class ConverterSample2 extends TestCase { - @Override - protected void setUp() throws Exception { - super.setUp(); - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - public final void testClassJunit() {} - - public final void testSetClassId() {} - - public final void testSetClassName() {} -} diff --git a/testng-core/src/test/java/ConverterSample4.java b/testng-core/src/test/java/ConverterSample4.java deleted file mode 100644 index 84a5660d7a..0000000000 --- a/testng-core/src/test/java/ConverterSample4.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Created on 12-Sep-2006 by micheb10 - * it is at the wrong location, but it's easier to leave it here. - * Also, do not change the line numbers since the test will make sure - * that the tags are generated in hardcoded line numbers - */ - -/** - * Sample file for the Javadocv annotations to Java 5 annotations converter for the default package - * - * @author micheb10 12-Sep-2006 - */ -public class ConverterSample4 { - /** - * This comment line should be preserved - * - * @testng.before-suite alwaysRun = "true" - */ - public void beforeSuiteAlwaysRun() { - // We are just checking appropriate annotations are added so we don't care about body - } - - /** @testng.test */ - public void plainTest() { - // Empty body - } - - /** - * @testng.test - * @testng.expected-exceptions value = "java.lang.NullPointerException - * java.lang.NumberFormatException" - */ - public void expectedExceptions() { - // Empty body - } - - /** @testng.test groups = "groupA groupB" */ - public void testGroups() { - // Empty body - } - - /** @testng.after-method */ - public void afterMethod() { - // Empty body - } - - /** - * This key should be preserved - * - * @author The author is a standard tag and should not be touched - * @testng.test groups = "groupA" dependsOnMethods = "expectedExceptions" timeOut="3000" - * unrecognised="futureProof" - * @version another standard tag should not be changed - * @testng.expected-exceptions value = "java.lang.NullPointerException - * java.lang.NumberFormatException" - */ - public void testEverything() {} - - /** @testng.data-provider name="test1" */ - public Object[][] dataProvider() { - return null; - } - - /** @testng.factory */ - @SuppressWarnings({"unchecked", "deprecation"}) - public Object[] factory() { - return null; - } -} diff --git a/testng-core/src/test/java/test/BaseTest.java b/testng-core/src/test/java/test/BaseTest.java index 260787c8f1..45f558162f 100644 --- a/testng-core/src/test/java/test/BaseTest.java +++ b/testng-core/src/test/java/test/BaseTest.java @@ -70,10 +70,6 @@ protected void setSuiteTimeOut(long n) { m_suite.setTimeOut(Long.toString(n)); } - protected void setJUnit(boolean f) { - getTest().setJUnit(f); - } - protected void setThreadCount(int count) { getTest().getSuite().setThreadCount(count); } diff --git a/testng-core/src/test/java/test/CommandLineTest.java b/testng-core/src/test/java/test/CommandLineTest.java deleted file mode 100644 index 6a853f420c..0000000000 --- a/testng-core/src/test/java/test/CommandLineTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package test; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.Stage; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.testng.Assert; -import org.testng.CommandLineArgs; -import org.testng.IInjectorFactory; -import org.testng.ITestContext; -import org.testng.ITestResult; -import org.testng.TestListenerAdapter; -import org.testng.TestNG; -import org.testng.annotations.Test; -import org.testng.internal.IConfiguration; -import org.testng.testhelper.OutputDirectoryPatch; -import test.sample.JUnitSample1; - -public class CommandLineTest { - - /** Test -junit */ - @Test(groups = {"current"}) - public void junitParsing() { - String[] argv = { - "-log", - "0", - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-junit", - "-testclass", - "test.sample.JUnitSample1" - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - List passed = tla.getPassedTests(); - assertEquals(passed.size(), 2); - String test1 = passed.get(0).getMethod().getMethodName(); - String test2 = passed.get(1).getMethod().getMethodName(); - - assertTrue( - JUnitSample1.EXPECTED1.equals(test1) && JUnitSample1.EXPECTED2.equals(test2) - || JUnitSample1.EXPECTED1.equals(test2) && JUnitSample1.EXPECTED2.equals(test1)); - } - - /** Test the absence of -junit */ - @Test(groups = {"current"}) - public void junitParsing2() { - String[] argv = { - "-log", "0", - "-d", OutputDirectoryPatch.getOutputDirectory(), - "-testclass", "test.sample.JUnitSample1" - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - List passed = tla.getPassedTests(); - assertEquals(passed.size(), 0); - } - - /** Test the ability to override the default command line Suite name */ - @Test(groups = {"current"}) - public void suiteNameOverride() { - String suiteName = "MySuiteName"; - String[] argv = { - "-log", - "0", - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-junit", - "-testclass", - "test.sample.JUnitSample1", - "-suitename", - suiteName - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - List contexts = tla.getTestContexts(); - assertTrue(contexts.size() > 0); - for (ITestContext context : contexts) { - assertEquals(context.getSuite().getName(), suiteName); - } - } - - /** Test the ability to override the default command line test name */ - @Test(groups = {"current"}) - public void testNameOverride() { - String testName = "My Test Name"; - String[] argv = { - "-log", - "0", - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-junit", - "-testclass", - "test.sample.JUnitSample1", - "-testname", - testName - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - List contexts = tla.getTestContexts(); - assertTrue(contexts.size() > 0); - for (ITestContext context : contexts) { - assertEquals(context.getName(), testName); - } - } - - @Test - public void testUseDefaultListenersArgument() { - TestNG.privateMain( - new String[] { - "-log", "0", "-usedefaultlisteners", "false", "-testclass", "test.sample.JUnitSample1" - }, - null); - } - - @Test - public void testMethodParameter() { - String[] argv = { - "-log", "0", - "-d", OutputDirectoryPatch.getOutputDirectory(), - "-methods", "test.sample.Sample2.method1,test.sample.Sample2.method3", - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - List passed = tla.getPassedTests(); - Assert.assertEquals(passed.size(), 2); - Assert.assertTrue( - (passed.get(0).getName().equals("method1") && passed.get(1).getName().equals("method3")) - || (passed.get(1).getName().equals("method1") - && passed.get(0).getName().equals("method3"))); - } - - @SuppressWarnings("deprecation") - @Test(description = "GITHUB-2207") - public void testInjectorFactoryCanBeConfiguredViaProperties() { - Map params = new HashMap<>(); - params.put(CommandLineArgs.DEPENDENCY_INJECTOR_FACTORY, TestInjectorFactory.class.getName()); - TestNG testNG = new TestNG(); - testNG.configure(params); - - IInjectorFactory resolvedInjectorFactory = retrieveInjectionMechanism(testNG); - Assert.assertEquals(resolvedInjectorFactory.getClass(), TestInjectorFactory.class); - } - - private static IInjectorFactory retrieveInjectionMechanism(TestNG testNG) { - try { - Field field = TestNG.class.getDeclaredField("m_configuration"); - field.setAccessible(true); - IConfiguration cfg = (IConfiguration) field.get(testNG); - return cfg.getInjectorFactory(); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static class TestInjectorFactory implements IInjectorFactory { - - @Override - @SuppressWarnings("deprecation") - public Injector getInjector(Stage stage, Module... modules) { - return null; - } - } -} diff --git a/testng-core/src/test/java/test/JUnit4Test.java b/testng-core/src/test/java/test/JUnit4Test.java deleted file mode 100644 index 04724c6d69..0000000000 --- a/testng-core/src/test/java/test/JUnit4Test.java +++ /dev/null @@ -1,92 +0,0 @@ -package test; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.testng.TestNG; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import test.junit4.*; -import test.junit4.issue2792.TestClassSample; -import test.junit4.issue2792.TestContextGatheringListener; - -public class JUnit4Test extends BaseTest { - - @BeforeMethod(dependsOnGroups = {"initTest"}) - public void initJUnitFlag() { - getTest().setJUnit(true); - } - - @DataProvider - public static Object[][] dp() { - return new Object[][] { - new Object[] { - new Class[] {JUnit4Sample2.class}, - JUnit4Sample2.EXPECTED, - JUnit4Sample2.FAILED, - JUnit4Sample2.SKIPPED - }, - new Object[] { - new Class[] {JUnit4SampleSuite.class}, - JUnit4SampleSuite.EXPECTED, - JUnit4SampleSuite.FAILED, - JUnit4SampleSuite.SKIPPED - }, - new Object[] { - new Class[] {JUnit4Child.class}, JUnit4Child.EXPECTED, new String[0], new String[0] - }, - new Object[] { - new Class[] {InheritedTest.class, JUnit4Sample1.class}, - new String[] {"t1", "t1"}, - new String[0], - new String[0] - }, - new Object[] { - new Class[] {JUnit4ParameterizedTest.class}, - JUnit4ParameterizedTest.EXPECTED, - JUnit4ParameterizedTest.FAILED, - JUnit4ParameterizedTest.SKIPPED - }, - new Object[] { - new Class[] {BeforeClassJUnit4Sample.class}, - new String[0], - new String[0], - new String[] {"myTest"} - }, - new Object[] { - new Class[] {ClassRuleJUnit4Sample.class}, - new String[0], - new String[0], - new String[] {"myTest"} - } - }; - } - - @Test(dataProvider = "dp") - public void testTests( - Class[] classes, - String[] expectedPassedTests, - String[] expectedFailedTests, - String[] expectedSkippedTests) { - addClasses(classes); - assert getTest().isJUnit(); - - run(); - - verifyPassedTests(expectedPassedTests); - verifyFailedTests(expectedFailedTests); - verifySkippedTests(expectedSkippedTests); - } - - @Test(description = "GITHUB-2792") - public void ensureTestContextAvailableForListeners() { - TestNG testng = new TestNG(); - testng.setTestClasses(new Class[] {TestClassSample.class}); - TestContextGatheringListener listener = new TestContextGatheringListener(); - testng.addListener(listener); - testng.setJUnit(true); - testng.run(); - assertThat(listener.isTestContextFoundOnTestStart()).isTrue(); - assertThat(listener.isTestContextFoundOnAfterInvocation()).isTrue(); - } -} diff --git a/testng-core/src/test/java/test/JUnitTest1.java b/testng-core/src/test/java/test/JUnitTest1.java deleted file mode 100644 index 3207721658..0000000000 --- a/testng-core/src/test/java/test/JUnitTest1.java +++ /dev/null @@ -1,115 +0,0 @@ -package test; - -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import test.junit.SetNameTest; -import test.sample.JUnitSample1; -import test.sample.JUnitSample2; - -/** - * This class - * - * @author Cedric Beust, May 5, 2004 - */ -public class JUnitTest1 extends BaseTest { - @BeforeMethod(dependsOnGroups = {"initTest"}) - public void initJUnitFlag() { - getTest().setJUnit(true); - } - - @Test - public void methodsThatStartWithTest() { - addClass("test.sample.JUnitSample1"); - assert getTest().isJUnit(); - - run(); - String[] passed = {JUnitSample1.EXPECTED1, JUnitSample1.EXPECTED2}; - String[] failed = {}; - - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Failed", failed, getFailedTests()); - } - - @Test - public void methodsWithSetup() { - addClass("test.sample.JUnitSample2"); - run(); - String[] passed = { - "testSample2ThatSetUpWasRun", - }; - String[] failed = {}; - - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Failed", failed, getFailedTests()); - } - - @Test - public void testSuite() { - addClass("test.sample.AllJUnitTests"); - run(); - String[] passed = { - JUnitSample1.EXPECTED1, /*JUnitSample1.EXPECTED2,*/ JUnitSample2.EXPECTED, - }; - String[] failed = {}; - - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Failed", failed, getFailedTests()); - } - - @Test - public void testNewInstance() { - addClass("test.sample.JUnitSample3"); - run(); - String[] passed = {"test1", "test2"}; - String[] failed = {}; - - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Failed", failed, getFailedTests()); - } - - @Test - public void setUpFailingShouldCauseMethodsToBeSkipped() { - addClass("test.junit.SetUpExceptionSampleTest"); - run(); - String[] passed = {}; - String[] failed = {"testM1" /*, "testM1", "tearDown"*/}; - String[] skipped = { - /*"testM1", "tearDown"*/ - }; - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Skipped", skipped, getSkippedTests()); - verifyTests("Failed", failed, getFailedTests()); - } - - @Test - public void setNameShouldBeInvoked() { - addClass("test.junit.SetNameTest"); - SetNameTest.m_ctorCount = 0; - run(); - String[] passed = { - "testFoo", "testBar", - }; - String[] failed = {}; - String[] skipped = {}; - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Skipped", skipped, getSkippedTests()); - verifyTests("Failed", failed, getFailedTests()); - - Assert.assertEquals( - SetNameTest.m_ctorCount, - 2, - "Expected 2 instances to be created, found " + SetNameTest.m_ctorCount); - } - - @Test - public void testAbstract() { - addClass("test.sample.JUnitSample4"); - run(); - String[] passed = {"testXY", "testXY", "testXY"}; - String[] failed = {}; - - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Failed", failed, getFailedTests()); - } -} diff --git a/testng-core/src/test/java/test/JUnitTestClassLoader.java b/testng-core/src/test/java/test/JUnitTestClassLoader.java deleted file mode 100644 index 1274347afd..0000000000 --- a/testng-core/src/test/java/test/JUnitTestClassLoader.java +++ /dev/null @@ -1,119 +0,0 @@ -package test; - -import static org.testng.Assert.*; - -import java.io.File; -import java.util.List; -import org.testng.*; -import org.testng.annotations.Test; -import org.testng.testhelper.CompiledCode; -import org.testng.testhelper.SimpleCompiler; -import org.testng.testhelper.SourceCode; - -public class JUnitTestClassLoader extends ClassLoader { - - @Test - public void testPassAndFail() throws Exception { - String src = - "import org.junit.Test;\n" - + "import static org.junit.Assert.*;\n" - + "public class SimpleTest1 {\n" - + " @Test\n" - + " public void test1() {\n" - + " assertEquals(42, 42);\n" - + " }\n" - + " @Test\n" - + " public void test2() {\n" - + " assertEquals(42, 0);\n" - + " }\n" - + "}\n"; - Listener listener = runJunitTest(src, "SimpleTest1"); - assertEquals(1, listener.success); - assertEquals(1, listener.failure); - } - - @Test - public void testFail() throws Exception { - String src = - "import org.junit.Test;\n" - + "import static org.junit.Assert.*;\n" - + "public class SimpleTest2 {\n" - + " @Test\n" - + " public void test() {\n" - + " assertEquals(42, 0);\n" - + " }\n" - + "}\n"; - Listener listener = runJunitTest(src, "SimpleTest2"); - assertEquals(0, listener.success); - assertEquals(1, listener.failure); - } - - @Test - public void testPass() throws Exception { - String src = - "import org.junit.Test;\n" - + "import static org.junit.Assert.*;\n" - + "public class SimpleTest3 {\n" - + " @Test\n" - + " public void test() {\n" - + " assertEquals(42, 42);\n" - + " }\n" - + "}\n"; - Listener listener = runJunitTest(src, "SimpleTest3"); - assertEquals(1, listener.success); - assertEquals(0, listener.failure); - } - - private Listener runJunitTest(String src, String name) throws Exception { - TestNG tng = new TestNG(false); - Class testClass = compile(src, name); - Listener listener = new Listener(); - tng.setJUnit(true); - tng.addClassLoader(testClass.getClassLoader()); - assertNotEquals( - testClass.getClassLoader(), - this.getClass().getClassLoader(), - "JUnit test must be loaded by a different classloader"); - try { - this.getClass().getClassLoader().loadClass(testClass.getName()); - fail("it must be imposiible to load JUnit test by current classloader"); - } catch (ClassNotFoundException c) { - } - - tng.setTestClasses(new Class[] {testClass}); - tng.addListener(listener); - tng.run(); - return listener; - } - - private Class compile(String src, String name) throws Exception { - File directory = SimpleCompiler.createTempDir(); - SourceCode sourceCode = new SourceCode(name, src, directory, false); - List compiledCode = SimpleCompiler.compileSourceCode(sourceCode); - byte[] bytes = compiledCode.get(0).getByteCode(); - return defineClass(name, bytes, 0, bytes.length); - } - - private static class Listener implements ITestListener { - public int success = 0; - public int failure = 0; - - public void onTestSuccess(ITestResult result) { - success++; - } - - public void onTestFailure(ITestResult result) { - failure++; - } - - public void onTestStart(ITestResult result) {} - - public void onTestSkipped(ITestResult result) {} - - public void onTestFailedButWithinSuccessPercentage(ITestResult result) {} - - public void onStart(ITestContext context) {} - - public void onFinish(ITestContext context) {} - } -} diff --git a/testng-core/src/test/java/test/github1405/JUnitTestClassSample.java b/testng-core/src/test/java/test/github1405/JUnitTestClassSample.java deleted file mode 100644 index 59e7f59b21..0000000000 --- a/testng-core/src/test/java/test/github1405/JUnitTestClassSample.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.github1405; - -import org.junit.Test; - -public class JUnitTestClassSample { - @Test - public void testMethod() {} -} diff --git a/testng-core/src/test/java/test/github1405/TestExclusionOfMainMethod.java b/testng-core/src/test/java/test/github1405/TestExclusionOfMainMethod.java deleted file mode 100644 index 60827e7678..0000000000 --- a/testng-core/src/test/java/test/github1405/TestExclusionOfMainMethod.java +++ /dev/null @@ -1,26 +0,0 @@ -package test.github1405; - -import org.testng.Assert; -import org.testng.TestNG; -import org.testng.annotations.Test; -import org.testng.xml.XmlSuite; -import test.SimpleBaseTest; - -public class TestExclusionOfMainMethod extends SimpleBaseTest { - @Test - public void testMainMethodExclusion() { - TestNG tng = create(TestClassSample.class); - tng.run(); - Assert.assertEquals(tng.getStatus(), 0); - } - - @Test - public void testMainMethodExclusionForJunit() { - XmlSuite xmlSuite = createXmlSuite("suite"); - xmlSuite.setJunit(true); - createXmlTest(xmlSuite, "test", JUnitTestClassSample.class); - TestNG tng = create(xmlSuite); - tng.run(); - Assert.assertEquals(tng.getStatus(), 0); - } -} diff --git a/testng-core/src/test/java/test/junit/BaseTest.java b/testng-core/src/test/java/test/junit/BaseTest.java deleted file mode 100644 index 6dc73b08d9..0000000000 --- a/testng-core/src/test/java/test/junit/BaseTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -/** - * Base JUnit test case to verify TestNG handles TestCase hierarchies properly. - * - * @author mperham - */ -public abstract class BaseTest extends TestCase { - - private static int setUpInvokeCount = 0; - private static int tearDownInvokeCount = 0; - - public BaseTest(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - setUpInvokeCount++; - } - - @Override - protected void tearDown() throws Exception { - tearDownInvokeCount++; - } - - public abstract void testA(); - - public abstract void testB(); - - public static int getSetUpInvokeCount() { - return setUpInvokeCount; - } - - public static int getTearDownInvokeCount() { - return tearDownInvokeCount; - } -} diff --git a/testng-core/src/test/java/test/junit/JUnitConstructorTest.java b/testng-core/src/test/java/test/junit/JUnitConstructorTest.java deleted file mode 100644 index 212c8331a6..0000000000 --- a/testng-core/src/test/java/test/junit/JUnitConstructorTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -/** - * Test that the correct number of constructors is called - * - *

Created on Aug 9, 2005 - * - * @author cbeust - */ -public class JUnitConstructorTest extends TestCase { - private static int m_constructorCount = 0; - private static int m_createCount = 0; - private static int m_queryCount = 0; - - public JUnitConstructorTest(/*String string */ ) { - m_constructorCount++; - } - - public void testCreate() { - m_createCount++; - } - - public void testQuery() { - m_queryCount++; - } - - @Override - public void tearDown() { - assertEquals(3, m_constructorCount); - assertTrue( - (1 == m_createCount && 0 == m_queryCount) || (0 == m_createCount && 1 == m_queryCount)); - } -} diff --git a/testng-core/src/test/java/test/junit/JUnitEmptyTest.java b/testng-core/src/test/java/test/junit/JUnitEmptyTest.java deleted file mode 100644 index c2e70c1de5..0000000000 --- a/testng-core/src/test/java/test/junit/JUnitEmptyTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JUnitEmptyTest extends TestCase { - - public JUnitEmptyTest(String name) { - super(name); - } - - public static Test suite() { - TestSuite s = new TestSuite(JUnitEmptyTest.class); - return s; - } -} diff --git a/testng-core/src/test/java/test/junit/MainSuite.java b/testng-core/src/test/java/test/junit/MainSuite.java deleted file mode 100644 index bda14b1c00..0000000000 --- a/testng-core/src/test/java/test/junit/MainSuite.java +++ /dev/null @@ -1,16 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class MainSuite { - public static Test suite() { - TestSuite suite = new TestSuite("MainSuite"); - - suite.addTest(Suite1.suite()); - suite.addTest(Suite2.suite()); - suite.addTest(Suite3.suite()); - - return suite; - } -} diff --git a/testng-core/src/test/java/test/junit/SetNameTest.java b/testng-core/src/test/java/test/junit/SetNameTest.java deleted file mode 100644 index f7e5f65fce..0000000000 --- a/testng-core/src/test/java/test/junit/SetNameTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; -import org.testng.Assert; - -public class SetNameTest extends TestCase { - public static int m_ctorCount = 0; - - public SetNameTest() { - m_ctorCount++; - } - - @Override - public void setName(String name) { - super.setName(name); - } - - public void testFoo() { - Assert.assertEquals("testFoo", getName()); - } - - public void testBar() { - Assert.assertEquals("testBar", getName()); - } -} diff --git a/testng-core/src/test/java/test/junit/SetUpExceptionSampleTest.java b/testng-core/src/test/java/test/junit/SetUpExceptionSampleTest.java deleted file mode 100644 index a50d36d31c..0000000000 --- a/testng-core/src/test/java/test/junit/SetUpExceptionSampleTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class SetUpExceptionSampleTest extends TestCase { - - @Override - protected void setUp() throws Exception { - throw new RuntimeException(); - } - - public void testM1() {} - - @Override - protected void tearDown() throws Exception {} -} diff --git a/testng-core/src/test/java/test/junit/SetUpExceptionTest.java b/testng-core/src/test/java/test/junit/SetUpExceptionTest.java deleted file mode 100644 index f9e20e1da2..0000000000 --- a/testng-core/src/test/java/test/junit/SetUpExceptionTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package test.junit; - -import org.testng.annotations.Test; - -public class SetUpExceptionTest extends test.BaseTest { - - @Test - public void setUpFailingShouldCauseMethodsToBeSkipped() { - addClass("test.junit.SetUpExceptionSampleTest"); - setJUnit(true); - run(); - String[] passed = {}; - String[] failed = {"setUp"}; - String[] skipped = {"testM1", "tearDown"}; - verifyTests("Passed", passed, getPassedTests()); - verifyTests("Skipped", skipped, getSkippedTests()); - verifyTests("Failed", failed, getFailedTests()); - } -} diff --git a/testng-core/src/test/java/test/junit/Suite1.java b/testng-core/src/test/java/test/junit/Suite1.java deleted file mode 100644 index 6071c36ae4..0000000000 --- a/testng-core/src/test/java/test/junit/Suite1.java +++ /dev/null @@ -1,17 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class Suite1 { - public Suite1(String s) { - // dummy - } - - public static Test suite() { - TestSuite suite = new TestSuite("JUnitSuite1"); - suite.addTestSuite(TestAa.class); - suite.addTestSuite(TestAb.class); - return suite; - } -} diff --git a/testng-core/src/test/java/test/junit/Suite2.java b/testng-core/src/test/java/test/junit/Suite2.java deleted file mode 100644 index 39637045ba..0000000000 --- a/testng-core/src/test/java/test/junit/Suite2.java +++ /dev/null @@ -1,14 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class Suite2 { - public static Test suite() { - TestSuite suite = new TestSuite("Suite2"); - suite.addTestSuite(TestAc.class); - suite.addTestSuite(TestAd.class); - suite.addTest(Suite3.suite()); - return suite; - } -} diff --git a/testng-core/src/test/java/test/junit/Suite3.java b/testng-core/src/test/java/test/junit/Suite3.java deleted file mode 100644 index 56c41b93cf..0000000000 --- a/testng-core/src/test/java/test/junit/Suite3.java +++ /dev/null @@ -1,12 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class Suite3 { - public static Test suite() { - TestSuite suite = new TestSuite("Suite3"); - suite.addTest(Suite4.suite()); - return suite; - } -} diff --git a/testng-core/src/test/java/test/junit/Suite4.java b/testng-core/src/test/java/test/junit/Suite4.java deleted file mode 100644 index 40c18b009c..0000000000 --- a/testng-core/src/test/java/test/junit/Suite4.java +++ /dev/null @@ -1,13 +0,0 @@ -package test.junit; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class Suite4 { - public static Test suite() { - TestSuite suite = new TestSuite("Suite4"); - suite.addTestSuite(TestAe.class); - suite.addTestSuite(TestAf.class); - return suite; - } -} diff --git a/testng-core/src/test/java/test/junit/TestAa.java b/testng-core/src/test/java/test/junit/TestAa.java deleted file mode 100644 index ef6d1dfc4d..0000000000 --- a/testng-core/src/test/java/test/junit/TestAa.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAa extends TestCase { - - public void testAa1() {} -} diff --git a/testng-core/src/test/java/test/junit/TestAb.java b/testng-core/src/test/java/test/junit/TestAb.java deleted file mode 100644 index c393733aac..0000000000 --- a/testng-core/src/test/java/test/junit/TestAb.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAb extends TestCase { - - public void testAb1() {} -} diff --git a/testng-core/src/test/java/test/junit/TestAc.java b/testng-core/src/test/java/test/junit/TestAc.java deleted file mode 100644 index 1313912f12..0000000000 --- a/testng-core/src/test/java/test/junit/TestAc.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAc extends TestCase { - - public void testAc1() {} -} diff --git a/testng-core/src/test/java/test/junit/TestAd.java b/testng-core/src/test/java/test/junit/TestAd.java deleted file mode 100644 index 7bfdc0e4d3..0000000000 --- a/testng-core/src/test/java/test/junit/TestAd.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAd extends TestCase { - - public void testAd1() {} -} diff --git a/testng-core/src/test/java/test/junit/TestAe.java b/testng-core/src/test/java/test/junit/TestAe.java deleted file mode 100644 index b7cd375c25..0000000000 --- a/testng-core/src/test/java/test/junit/TestAe.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAe extends TestCase { - - public void testAe1() {} -} diff --git a/testng-core/src/test/java/test/junit/TestAf.java b/testng-core/src/test/java/test/junit/TestAf.java deleted file mode 100644 index 19140373cb..0000000000 --- a/testng-core/src/test/java/test/junit/TestAf.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit; - -import junit.framework.TestCase; - -public class TestAf extends TestCase { - - public void testAf1() {} -} diff --git a/testng-core/src/test/java/test/junit/testsetup/ATest.java b/testng-core/src/test/java/test/junit/testsetup/ATest.java deleted file mode 100644 index 7f56c71c3a..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/ATest.java +++ /dev/null @@ -1,11 +0,0 @@ -package test.junit.testsetup; - -import junit.framework.TestCase; - -public class ATest extends TestCase { - public void testIt() { - System.out.println("A.testIt()"); - Data d = TestSuiteContainerWrapper.getData(); - assertEquals(3, d.i); - } -} diff --git a/testng-core/src/test/java/test/junit/testsetup/Data.java b/testng-core/src/test/java/test/junit/testsetup/Data.java deleted file mode 100644 index bb0d52e455..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/Data.java +++ /dev/null @@ -1,5 +0,0 @@ -package test.junit.testsetup; - -public class Data { - public int i = 3; -} diff --git a/testng-core/src/test/java/test/junit/testsetup/LayerATestSuite.java b/testng-core/src/test/java/test/junit/testsetup/LayerATestSuite.java deleted file mode 100644 index db9e6a8b89..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/LayerATestSuite.java +++ /dev/null @@ -1,15 +0,0 @@ -package test.junit.testsetup; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class LayerATestSuite { - public static Test suite() { - TestSuite suite = new TestSuite("Layer A Test Suite"); - - suite.addTestSuite(ATest.class); - - TestSuiteContainerWrapper wrapper = new TestSuiteContainerWrapper(suite, Data.class); - return wrapper; - } -} diff --git a/testng-core/src/test/java/test/junit/testsetup/LoggingTestSuite.java b/testng-core/src/test/java/test/junit/testsetup/LoggingTestSuite.java deleted file mode 100644 index bd40e0d150..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/LoggingTestSuite.java +++ /dev/null @@ -1,21 +0,0 @@ -package test.junit.testsetup; - -import junit.framework.Test; -import junit.framework.TestResult; -import junit.framework.TestSuite; - -public class LoggingTestSuite extends TestSuite { - public LoggingTestSuite(String string) { - super(string); - } - - @Override - public void run(TestResult result) { - super.run(result); - } - - @Override - public void runTest(Test test, TestResult result) { - super.runTest(test, result); - } -} diff --git a/testng-core/src/test/java/test/junit/testsetup/SmokeSuite.java b/testng-core/src/test/java/test/junit/testsetup/SmokeSuite.java deleted file mode 100644 index 30b9aa4704..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/SmokeSuite.java +++ /dev/null @@ -1,27 +0,0 @@ -package test.junit.testsetup; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class SmokeSuite extends LoggingTestSuite { - public static void main(String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static Test suite() { - TestSuite suite = new TestSuite("Smoke Test Suite"); - - suite.addTest(LayerATestSuite.suite()); - - return suite; - } - - // public SmokeSuite() - // { - // this("SmokeSuite"); - // } - - public SmokeSuite(String name) { - super(name); - } -} diff --git a/testng-core/src/test/java/test/junit/testsetup/TestSuiteContainerWrapper.java b/testng-core/src/test/java/test/junit/testsetup/TestSuiteContainerWrapper.java deleted file mode 100644 index ec015872f5..0000000000 --- a/testng-core/src/test/java/test/junit/testsetup/TestSuiteContainerWrapper.java +++ /dev/null @@ -1,40 +0,0 @@ -package test.junit.testsetup; - -import junit.extensions.TestSetup; -import junit.framework.TestSuite; -import org.testng.internal.objects.InstanceCreator; - -public class TestSuiteContainerWrapper extends TestSetup { - private static Data INSTANCE = null; - private static TestSuite _test = null; - private static Class dataImpl = null; - - public TestSuiteContainerWrapper(TestSuite testSuite, Class dataImpl) { - super(testSuite); - _test = testSuite; - TestSuiteContainerWrapper.dataImpl = dataImpl; - } - - public static Data getData() { - return INSTANCE; - } - - @Override - protected void setUp() throws Exception { - System.out.println("setup"); - INSTANCE = InstanceCreator.newInstance(dataImpl); - } - - @Override - protected void tearDown() throws Exception { - System.out.println("teardown"); - - INSTANCE = null; - - System.out.println( - _test.countTestCases() - + " test cases defined by \"" - + _test.getName() - + "\" were executed."); - } -} diff --git a/testng-core/src/test/java/test/junit4/BeforeClassJUnit4Sample.java b/testng-core/src/test/java/test/junit4/BeforeClassJUnit4Sample.java deleted file mode 100644 index c3667a456f..0000000000 --- a/testng-core/src/test/java/test/junit4/BeforeClassJUnit4Sample.java +++ /dev/null @@ -1,23 +0,0 @@ -package test.junit4; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -public class BeforeClassJUnit4Sample { - - @BeforeClass - public static void before() { - throw new IllegalArgumentException("before failed"); - } - - @AfterClass - public static void after() { - // throw new IllegalArgumentException("after failed"); - } - - @Test - public void myTest() { - System.out.println("yay!"); - } -} diff --git a/testng-core/src/test/java/test/junit4/ClassRuleJUnit4Sample.java b/testng-core/src/test/java/test/junit4/ClassRuleJUnit4Sample.java deleted file mode 100644 index 84d073d632..0000000000 --- a/testng-core/src/test/java/test/junit4/ClassRuleJUnit4Sample.java +++ /dev/null @@ -1,27 +0,0 @@ -package test.junit4; - -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.rules.ExternalResource; - -public class ClassRuleJUnit4Sample { - - @ClassRule - public static ExternalResource resource = - new ExternalResource() { - @Override - protected void before() throws Throwable { - throw new IllegalArgumentException("before"); - } - - @Override - protected void after() { - throw new IllegalArgumentException("after"); - } - }; - - @Test - public void myTest() { - System.out.println("yay!"); - } -} diff --git a/testng-core/src/test/java/test/junit4/InheritedTest.java b/testng-core/src/test/java/test/junit4/InheritedTest.java deleted file mode 100644 index fffa518fa2..0000000000 --- a/testng-core/src/test/java/test/junit4/InheritedTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package test.junit4; - -/** @author lukas */ -public class InheritedTest extends JUnit4Sample1 {} diff --git a/testng-core/src/test/java/test/junit4/JUnit4Child.java b/testng-core/src/test/java/test/junit4/JUnit4Child.java deleted file mode 100644 index b208243f23..0000000000 --- a/testng-core/src/test/java/test/junit4/JUnit4Child.java +++ /dev/null @@ -1,9 +0,0 @@ -package test.junit4; - -import org.junit.runners.Suite; - -/** @author lukas */ -@Suite.SuiteClasses({JUnit4Sample1.class}) -public class JUnit4Child extends JUnit4SampleSuite { - public static final String[] EXPECTED = {"t1"}; -} diff --git a/testng-core/src/test/java/test/junit4/JUnit4ParameterizedTest.java b/testng-core/src/test/java/test/junit4/JUnit4ParameterizedTest.java deleted file mode 100644 index 0db1599000..0000000000 --- a/testng-core/src/test/java/test/junit4/JUnit4ParameterizedTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package test.junit4; - -import java.util.Arrays; -import java.util.Collection; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -@RunWith(Parameterized.class) -public class JUnit4ParameterizedTest { - - public static final String[] EXPECTED = {"t2[0]", "t2[1]", "t4[0]"}; - public static final String[] SKIPPED = {"t3[0]", "t3[1]", "ta[0]", "ta[1]"}; - public static final String[] FAILED = {"t4[1]", "tf[0]", "tf[1]"}; - - private int param; - - @Parameters - public static Collection data() { - return Arrays.asList(new Object[][] {{1}, {5}}); - } - - public JUnit4ParameterizedTest(int param) { - this.param = param; - } - - @Test - public void t2() {} - - @Test - @Ignore - public void t3() {} - - @Test - public void t4() { - if (param == 5) { - Assert.fail("a test"); - } - } - - @Test - public void tf() { - Assert.fail("a test"); - } - - @Test - public void ta() { - Assume.assumeTrue(false); - } -} diff --git a/testng-core/src/test/java/test/junit4/JUnit4Sample1.java b/testng-core/src/test/java/test/junit4/JUnit4Sample1.java deleted file mode 100644 index 551e321115..0000000000 --- a/testng-core/src/test/java/test/junit4/JUnit4Sample1.java +++ /dev/null @@ -1,10 +0,0 @@ -package test.junit4; - -import org.junit.Test; - -/** @author lukas */ -public class JUnit4Sample1 { - - @Test - public void t1() {} -} diff --git a/testng-core/src/test/java/test/junit4/JUnit4Sample2.java b/testng-core/src/test/java/test/junit4/JUnit4Sample2.java deleted file mode 100644 index 82c98b4808..0000000000 --- a/testng-core/src/test/java/test/junit4/JUnit4Sample2.java +++ /dev/null @@ -1,34 +0,0 @@ -package test.junit4; - -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.Test; - -/** @author lukas */ -public class JUnit4Sample2 { - - public static final String[] EXPECTED = {"t2", "t4"}; - public static final String[] SKIPPED = {"t3", "ta"}; - public static final String[] FAILED = {"tf"}; - - @Test - public void t2() {} - - @Test - @Ignore - public void t3() {} - - @Test - public void t4() {} - - @Test - public void tf() { - Assert.fail("a test"); - } - - @Test - public void ta() { - Assume.assumeTrue(false); - } -} diff --git a/testng-core/src/test/java/test/junit4/JUnit4SampleSuite.java b/testng-core/src/test/java/test/junit4/JUnit4SampleSuite.java deleted file mode 100644 index 0bc18600cd..0000000000 --- a/testng-core/src/test/java/test/junit4/JUnit4SampleSuite.java +++ /dev/null @@ -1,14 +0,0 @@ -package test.junit4; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** @author lukas */ -@RunWith(Suite.class) -@Suite.SuiteClasses({JUnit4Sample1.class, JUnit4Sample2.class}) -public class JUnit4SampleSuite { - - public static final String[] EXPECTED = {"t1", "t2", "t4"}; - public static final String[] SKIPPED = {"t3", "ta"}; - public static final String[] FAILED = {"tf"}; -} diff --git a/testng-core/src/test/java/test/junit4/issue2792/TestClassSample.java b/testng-core/src/test/java/test/junit4/issue2792/TestClassSample.java deleted file mode 100644 index d7af869d3b..0000000000 --- a/testng-core/src/test/java/test/junit4/issue2792/TestClassSample.java +++ /dev/null @@ -1,9 +0,0 @@ -package test.junit4.issue2792; - -import org.junit.Test; - -public class TestClassSample { - - @Test - public void testMethod() {} -} diff --git a/testng-core/src/test/java/test/junit4/issue2792/TestContextGatheringListener.java b/testng-core/src/test/java/test/junit4/issue2792/TestContextGatheringListener.java deleted file mode 100644 index 0ced6a78e8..0000000000 --- a/testng-core/src/test/java/test/junit4/issue2792/TestContextGatheringListener.java +++ /dev/null @@ -1,31 +0,0 @@ -package test.junit4.issue2792; - -import java.util.Objects; -import org.testng.IInvokedMethod; -import org.testng.IInvokedMethodListener; -import org.testng.ITestListener; -import org.testng.ITestResult; - -public class TestContextGatheringListener implements IInvokedMethodListener, ITestListener { - - private boolean testContextFoundOnTestStart = false; - private boolean testContextFoundOnAfterInvocation = false; - - public boolean isTestContextFoundOnAfterInvocation() { - return testContextFoundOnAfterInvocation; - } - - public boolean isTestContextFoundOnTestStart() { - return testContextFoundOnTestStart; - } - - @Override - public void afterInvocation(IInvokedMethod method, ITestResult testResult) { - testContextFoundOnAfterInvocation = Objects.nonNull(testResult.getTestContext()); - } - - @Override - public void onTestStart(ITestResult result) { - testContextFoundOnTestStart = Objects.nonNull(result.getTestContext()); - } -} diff --git a/testng-core/src/test/java/test/junit4/listeners/Issue323JUnitInvocationListener.java b/testng-core/src/test/java/test/junit4/listeners/Issue323JUnitInvocationListener.java deleted file mode 100644 index fd1bd810db..0000000000 --- a/testng-core/src/test/java/test/junit4/listeners/Issue323JUnitInvocationListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package test.junit4.listeners; - -import java.util.ArrayList; -import java.util.List; -import org.testng.IInvokedMethod; -import org.testng.IInvokedMethodListener; -import org.testng.ITestResult; - -public class Issue323JUnitInvocationListener implements IInvokedMethodListener { - public static List messages = new ArrayList<>(); - - @Override - public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { - messages.add("beforeInvocation"); - } - - @Override - public void afterInvocation(IInvokedMethod method, ITestResult testResult) { - messages.add("afterInvocation"); - } -} diff --git a/testng-core/src/test/java/test/junit4/listeners/Issue323TestRunner.java b/testng-core/src/test/java/test/junit4/listeners/Issue323TestRunner.java deleted file mode 100644 index c25dd5511e..0000000000 --- a/testng-core/src/test/java/test/junit4/listeners/Issue323TestRunner.java +++ /dev/null @@ -1,21 +0,0 @@ -package test.junit4.listeners; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.testng.ITestNGListener; -import org.testng.TestNG; -import org.testng.annotations.Test; -import test.SimpleBaseTest; - -public class Issue323TestRunner extends SimpleBaseTest { - @Test - public void testMethod() { - TestNG testng = create(Issue323TestSample.class); - Issue323JUnitInvocationListener listener = new Issue323JUnitInvocationListener(); - testng.addListener((ITestNGListener) listener); - testng.setJUnit(true); - testng.run(); - assertThat(Issue323JUnitInvocationListener.messages) - .containsExactly("beforeInvocation", "afterInvocation"); - } -} diff --git a/testng-core/src/test/java/test/junit4/listeners/Issue323TestSample.java b/testng-core/src/test/java/test/junit4/listeners/Issue323TestSample.java deleted file mode 100644 index 8ecac7e7a3..0000000000 --- a/testng-core/src/test/java/test/junit4/listeners/Issue323TestSample.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.junit4.listeners; - -import org.junit.Test; - -public class Issue323TestSample { - @Test - public void testMethod() {} -} diff --git a/testng-core/src/test/java/test/mixed/JUnit3Test1.java b/testng-core/src/test/java/test/mixed/JUnit3Test1.java deleted file mode 100644 index af43026019..0000000000 --- a/testng-core/src/test/java/test/mixed/JUnit3Test1.java +++ /dev/null @@ -1,15 +0,0 @@ -package test.mixed; - -import junit.framework.TestCase; - -/** @author lukas */ -public class JUnit3Test1 extends TestCase { - - public JUnit3Test1(String name) { - super(name); - } - - public void testA() {} - - public void testB() {} -} diff --git a/testng-core/src/test/java/test/mixed/JUnit4Test1.java b/testng-core/src/test/java/test/mixed/JUnit4Test1.java deleted file mode 100644 index 794b84ad47..0000000000 --- a/testng-core/src/test/java/test/mixed/JUnit4Test1.java +++ /dev/null @@ -1,13 +0,0 @@ -package test.mixed; - -import org.junit.Test; - -/** @author lukas */ -public class JUnit4Test1 { - - @Test - public void atest() {} - - @Test - public void bTest() {} -} diff --git a/testng-core/src/test/java/test/mixed/MixedTest.java b/testng-core/src/test/java/test/mixed/MixedTest.java deleted file mode 100644 index db757f2700..0000000000 --- a/testng-core/src/test/java/test/mixed/MixedTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package test.mixed; - -import org.testng.Assert; -import org.testng.TestListenerAdapter; -import org.testng.TestNG; -import org.testng.annotations.Test; -import org.testng.testhelper.OutputDirectoryPatch; -import test.BaseTest; - -/** @author lukas */ -public class MixedTest extends BaseTest { - @Test - public void mixedWithExcludedGroups() { - String[] argv = { - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-log", - "0", - "-mixed", - "-groups", - "unit", - "-excludegroups", - "ignore", - "-testclass", - "test.mixed.JUnit3Test1,test.mixed.JUnit4Test1,test.mixed.TestNGTest1,test.mixed.TestNGGroups" - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - Assert.assertEquals( - tla.getPassedTests().size(), - 5); // 2 from junit3test1, 2 from junit4test1, 0 from testngtest1 (no groups), 1 from - // testnggroups (1 is included, 1 is excluded) - Assert.assertEquals(tla.getFailedTests().size(), 0); - } - - @Test - public void mixedClasses() { - String[] argv = { - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-log", - "0", - "-mixed", - "-testclass", - "test.mixed.JUnit3Test1,test.mixed.JUnit4Test1,test.mixed.TestNGTest1" - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - Assert.assertEquals(tla.getPassedTests().size(), 6); - Assert.assertEquals(tla.getFailedTests().size(), 0); - } - - @Test - public void mixedMethods() { - String[] argv = { - "-d", - OutputDirectoryPatch.getOutputDirectory(), - "-mixed", - "-log", - "0", - "-methods", - "test.mixed.JUnit3Test1.testB,test.mixed.JUnit4Test1.atest,test.mixed.TestNGTest1.tngCustomTest1" - }; - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG.privateMain(argv, tla); - - Assert.assertEquals(tla.getPassedTests().size(), 3); - Assert.assertEquals(tla.getFailedTests().size(), 0); - } -} diff --git a/testng-core/src/test/java/test/mixed/TestNGGroups.java b/testng-core/src/test/java/test/mixed/TestNGGroups.java deleted file mode 100644 index 38ae5c9f67..0000000000 --- a/testng-core/src/test/java/test/mixed/TestNGGroups.java +++ /dev/null @@ -1,12 +0,0 @@ -package test.mixed; - -import org.testng.annotations.Test; - -@Test(groups = {"unit"}) -public class TestNGGroups { - @Test - public void tngTest1() {} - - @Test(groups = {"ignore"}) - public void tngShouldBeIgnored() {} -} diff --git a/testng-core/src/test/java/test/mixed/TestNGTest1.java b/testng-core/src/test/java/test/mixed/TestNGTest1.java deleted file mode 100644 index d816607702..0000000000 --- a/testng-core/src/test/java/test/mixed/TestNGTest1.java +++ /dev/null @@ -1,13 +0,0 @@ -package test.mixed; - -import org.testng.annotations.Test; - -/** @author lukas */ -public class TestNGTest1 { - - @Test - public void tngTest1() {} - - @Test - public void tngCustomTest1() {} -} diff --git a/testng-core/src/test/java/test/reports/issue2069/Dummy1.java b/testng-core/src/test/java/test/reports/issue2069/Dummy1.java deleted file mode 100755 index a8cd603fa5..0000000000 --- a/testng-core/src/test/java/test/reports/issue2069/Dummy1.java +++ /dev/null @@ -1,13 +0,0 @@ -package test.reports.issue2069; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class Dummy1 extends TestSuite { - - public static Test suite() { - final TestSuite suite = new TestSuite("Failing report"); - suite.addTestSuite(Dummy3.class); - return suite; - } -} diff --git a/testng-core/src/test/java/test/reports/issue2069/Dummy2.java b/testng-core/src/test/java/test/reports/issue2069/Dummy2.java deleted file mode 100755 index f0b5b4cdd1..0000000000 --- a/testng-core/src/test/java/test/reports/issue2069/Dummy2.java +++ /dev/null @@ -1,8 +0,0 @@ -package test.reports.issue2069; - -import junit.framework.TestCase; - -public class Dummy2 extends TestCase { - - public void testScheduleDelete() {} -} diff --git a/testng-core/src/test/java/test/reports/issue2069/Dummy3.java b/testng-core/src/test/java/test/reports/issue2069/Dummy3.java deleted file mode 100755 index dc0277cd1b..0000000000 --- a/testng-core/src/test/java/test/reports/issue2069/Dummy3.java +++ /dev/null @@ -1,18 +0,0 @@ -package test.reports.issue2069; - -import junit.framework.TestCase; -import org.junit.Assert; -import org.junit.Test; - -public class Dummy3 extends TestCase { - - @Test - public void testFails() { - Assert.assertEquals("test3 assertion that will fail", "1", "2"); - } - - @Test - public void testSucceeds() { - Assert.assertEquals("test3 assertion", "1", "1"); - } -} diff --git a/testng-core/src/test/java/test/reports/issue2069/Dummy4.java b/testng-core/src/test/java/test/reports/issue2069/Dummy4.java deleted file mode 100755 index 9b19e3cf12..0000000000 --- a/testng-core/src/test/java/test/reports/issue2069/Dummy4.java +++ /dev/null @@ -1,9 +0,0 @@ -package test.reports.issue2069; - -import org.testng.annotations.Test; - -public class Dummy4 { - - @Test - public void testngTest() {} -} diff --git a/testng-core/src/test/java/test/reports/issue2069/IssueTest.java b/testng-core/src/test/java/test/reports/issue2069/IssueTest.java deleted file mode 100644 index 8a3990c70b..0000000000 --- a/testng-core/src/test/java/test/reports/issue2069/IssueTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package test.reports.issue2069; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; -import org.testng.TestNG; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import org.testng.xml.XmlSuite; -import test.SimpleBaseTest; - -public class IssueTest extends SimpleBaseTest { - - private PrintStream currentError = System.err; - private final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - @BeforeMethod - public void setup() throws UnsupportedEncodingException { - PrintStream ps = new PrintStream(baos, true, "UTF-8"); - System.setErr(ps); - } - - @AfterMethod(alwaysRun = true) - public void teardown() { - System.setErr(currentError); - } - - @Test - public void ensureNoExceptionsAriseFromReporters() { - XmlSuite xmlSuite = createXmlSuite("Not Failing TestSuite"); - createXmlTest(xmlSuite, "TestngTest", Dummy4.class); - createXmlTest(xmlSuite, "TestSuite", Dummy1.class).setJunit(true); - createXmlTest(xmlSuite, "TestCase", Dummy2.class).setJunit(true); - TestNG tng = create(xmlSuite); - tng.setUseDefaultListeners(true); - tng.run(); - String data = new String(baos.toByteArray(), StandardCharsets.UTF_8); - assertThat(data).doesNotContain("NullPointerException"); - } -} diff --git a/testng-core/src/test/resources/junit-suite.xml b/testng-core/src/test/resources/junit-suite.xml deleted file mode 100644 index b9324e67aa..0000000000 --- a/testng-core/src/test/resources/junit-suite.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/testng-core/src/test/resources/testng-all.xml b/testng-core/src/test/resources/testng-all.xml index 0c97ea6a82..9f14162f38 100644 --- a/testng-core/src/test/resources/testng-all.xml +++ b/testng-core/src/test/resources/testng-all.xml @@ -15,10 +15,6 @@ - - - - @@ -28,7 +24,7 @@ -