From 31a6810c58a5ab3948a7c025e96a0b1ff70ff1be Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Sat, 3 Dec 2022 22:56:08 +0530 Subject: [PATCH] Deprecate support for running JUnit tests Closes #2847 --- CHANGES.txt | 1 + .../src/main/java/org/testng/TestRunner.java | 14 +++++++++++++- .../java/org/testng/junit/IJUnitTestRunner.java | 7 ++++++- .../java/org/testng/junit/JUnit3TestClass.java | 5 ++++- .../java/org/testng/junit/JUnit3TestMethod.java | 4 ++++ .../org/testng/junit/JUnit3TestRecognizer.java | 5 ++++- .../testng/junit/JUnit4ConfigurationMethod.java | 4 ++++ .../java/org/testng/junit/JUnit4TestClass.java | 5 ++++- .../java/org/testng/junit/JUnit4TestMethod.java | 4 ++++ .../org/testng/junit/JUnit4TestRecognizer.java | 5 ++++- .../java/org/testng/junit/JUnit4TestRunner.java | 7 ++++++- .../java/org/testng/junit/JUnitMethodFinder.java | 8 ++++++-- .../main/java/org/testng/junit/JUnitTestClass.java | 4 ++++ .../java/org/testng/junit/JUnitTestFinder.java | 4 ++++ .../java/org/testng/junit/JUnitTestMethod.java | 4 ++++ .../java/org/testng/junit/JUnitTestRecognizer.java | 5 ++++- .../java/org/testng/junit/JUnitTestRunner.java | 7 ++++++- 17 files changed, 82 insertions(+), 11 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 18fa6fbbb0..b9f81b1ad9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,6 @@ Current Fixed: GITHUB-2792: JUnitTestClass sets XmlTest as null when running JUnit 4 Tests using TestNG (Krishnan Mahadevan) +Fixed: GITHUB-2847: Deprecate support for running JUnit tests (Krishnan Mahadevan) Fixed: GITHUB-2844: Deprecate support for running Spock Tests (Krishnan Mahadevan) Fixed: GITHUB-550: Weird @BeforeMethod and @AfterMethod behaviour with dependsOnMethods (Krishnan Mahadevan) Fixed: GITHUB-893: TestNG should provide an Api which allow to find all dependent of a specific test (Krishnan Mahadevan) diff --git a/testng-core/src/main/java/org/testng/TestRunner.java b/testng-core/src/main/java/org/testng/TestRunner.java index c1f5ef673c..6b00c2ca82 100644 --- a/testng-core/src/main/java/org/testng/TestRunner.java +++ b/testng-core/src/main/java/org/testng/TestRunner.java @@ -15,6 +15,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -646,7 +647,18 @@ 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(); @@ -656,7 +668,7 @@ private void privateRunJUnit() { // The resolution process is not specified in the JVM spec with a specific implementation, // so it can be eager => failure workers.add( - new IWorker() { + new IWorker<>() { /** @see TestMethodWorker#getTimeOut() */ @Override public long getTimeOut() { diff --git a/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java b/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java index 72d87e9127..462acfe530 100644 --- a/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java +++ b/testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java @@ -9,7 +9,12 @@ import org.testng.internal.ITestResultNotifier; import org.testng.internal.Utils; -/** An abstraction interface over JUnit test runners. */ +/** + * An abstraction interface over JUnit test runners. + * + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public interface IJUnitTestRunner { void setInvokedMethodListeners(Collection listener); diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java index abcbd49194..3c6c8c5315 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java @@ -2,7 +2,10 @@ import junit.framework.Test; -/** @author lukas */ +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit3TestClass extends JUnitTestClass { public JUnit3TestClass(Test test) { diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java index 1c6aad5731..b234c06992 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java @@ -6,6 +6,10 @@ import org.testng.internal.ConstructorOrMethod; import org.testng.internal.Utils; +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit3TestMethod extends JUnitTestMethod { public JUnit3TestMethod(ITestObjectFactory objectFactory, JUnitTestClass owner, Test test) { diff --git a/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java index a4498a2583..8709b7785b 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java @@ -4,7 +4,10 @@ import java.lang.reflect.Modifier; import junit.framework.Test; -/** @author lukas */ +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit3TestRecognizer implements JUnitTestRecognizer { public JUnit3TestRecognizer() {} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java index 87cfd2e551..73c11d03cf 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java @@ -3,6 +3,10 @@ import java.lang.reflect.Method; import org.testng.internal.ConstructorOrMethod; +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit4ConfigurationMethod extends ConstructorOrMethod { private final Class declaringClass; diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java index 3adbdee5fa..cdc4c38fd7 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java @@ -2,7 +2,10 @@ import org.junit.runner.Description; -/** @author lukas */ +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit4TestClass extends JUnitTestClass { public JUnit4TestClass(Description test) { diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java index cbdb0ef957..99a7b8cb71 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java @@ -7,6 +7,10 @@ import org.testng.internal.Utils; import org.testng.log4testng.Logger; +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit4TestMethod extends JUnitTestMethod { private static final AtomicBoolean warnOnce = new AtomicBoolean(false); diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java index eb1e84a408..a60775373f 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java @@ -4,7 +4,10 @@ import java.lang.reflect.Method; import org.junit.runner.RunWith; -/** @author lukas */ +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public final class JUnit4TestRecognizer implements JUnitTestRecognizer { public JUnit4TestRecognizer() {} diff --git a/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java b/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java index 86ca94331b..ddcc8a7dfe 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java +++ b/testng-core/src/main/java/org/testng/junit/JUnit4TestRunner.java @@ -16,7 +16,12 @@ import org.testng.internal.invokers.IInvocationStatus; import org.testng.internal.invokers.InvokedMethod; -/** A JUnit TestRunner that records/triggers all information/events necessary to TestNG. */ +/** + * A JUnit TestRunner that records/triggers all information/events necessary to TestNG. + * + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnit4TestRunner implements IJUnitTestRunner { private final ITestObjectFactory objectFactory; diff --git a/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java b/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java index 6669a1517f..9aa51c7252 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitMethodFinder.java @@ -18,8 +18,9 @@ * 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. * - * @since May 3, 2004 + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 */ +@Deprecated public class JUnitMethodFinder implements ITestMethodFinder { private final ITestObjectFactory objectFactory; @@ -119,7 +120,10 @@ public ITestNGMethod[] getAfterGroupsConfigurationMethods(Class testClass) { return new ITestNGMethod[0]; } } - +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@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 index 471905cda9..2db4f75875 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestClass.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitTestClass.java @@ -8,6 +8,10 @@ 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.6.2 + */ +@Deprecated public abstract class JUnitTestClass implements ITestClass { private List m_testMethods = Lists.newArrayList(); diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java b/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java index ce69b97017..d1f20a22cd 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitTestFinder.java @@ -4,6 +4,10 @@ import org.testng.internal.Utils; import org.testng.internal.objects.InstanceCreator; +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public final class JUnitTestFinder { private static final String JUNIT3_TEST = "junit.framework.Test"; diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java b/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java index ba12994da8..133a3fe894 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitTestMethod.java @@ -6,6 +6,10 @@ 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.6.2 + */ +@Deprecated public abstract class JUnitTestMethod extends BaseTestMethod { protected JUnitTestMethod( diff --git a/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java b/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java index cf8da128fb..54ee642bec 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitTestRecognizer.java @@ -1,6 +1,9 @@ package org.testng.junit; -/** @author lukas */ +/** + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@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 index 42002a2309..3f4581ab62 100644 --- a/testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java +++ b/testng-core/src/main/java/org/testng/junit/JUnitTestRunner.java @@ -20,7 +20,12 @@ import org.testng.internal.TestListenerHelper; import org.testng.internal.invokers.InvokedMethod; -/** A JUnit TestRunner that records/triggers all information/events necessary to TestNG. */ +/** + * A JUnit TestRunner that records/triggers all information/events necessary to TestNG. + * + * @deprecated - Support for running JUnit tests stands deprecated as of TestNG 7.6.2 + */ +@Deprecated public class JUnitTestRunner implements TestListener, IJUnitTestRunner { public static final String SUITE_METHODNAME = "suite";