Skip to content

Commit 7846c44

Browse files
committed
Deprecate support for running JUnit tests
Closes #2847
1 parent 8630a7e commit 7846c44

17 files changed

+82
-11
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Current
22
Fixed: GITHUB-2792: JUnitTestClass sets XmlTest as null when running JUnit 4 Tests using TestNG (Krishnan Mahadevan)
3+
Fixed: GITHUB-2847: Deprecate support for running JUnit tests (Krishnan Mahadevan)
34
Fixed: GITHUB-2844: Deprecate support for running Spock Tests (Krishnan Mahadevan)
45
Fixed: GITHUB-550: Weird @BeforeMethod and @AfterMethod behaviour with dependsOnMethods (Krishnan Mahadevan)
56
Fixed: GITHUB-893: TestNG should provide an Api which allow to find all dependent of a specific test (Krishnan Mahadevan)

testng-core/src/main/java/org/testng/TestRunner.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.concurrent.LinkedBlockingQueue;
1616
import java.util.concurrent.PriorityBlockingQueue;
1717
import java.util.concurrent.TimeUnit;
18+
import java.util.concurrent.atomic.AtomicBoolean;
1819
import java.util.concurrent.atomic.AtomicReference;
1920
import java.util.stream.Collectors;
2021
import java.util.stream.Stream;
@@ -646,7 +647,18 @@ private void invokeTestConfigurations(ITestNGMethod[] testConfigurationMethods)
646647

647648
private ITestNGMethod[] m_allJunitTestMethods = new ITestNGMethod[] {};
648649

650+
private static final AtomicBoolean warnOnce = new AtomicBoolean(false);
651+
649652
private void privateRunJUnit() {
653+
if (warnOnce.compareAndSet(false, true)) {
654+
String msg =
655+
"Support to run JUnit tests using TestNG stands deprecated "
656+
+ "and will be removed in future versions. You can now use the JUnit5 TestNG "
657+
+ "engine to run both JUnit and TestNG tests. For more information refer to "
658+
+ "https://github.com/junit-team/testng-engine .";
659+
Logger.getLogger(TestRunner.class).warn(msg);
660+
}
661+
650662
final ClassInfoMap cim = new ClassInfoMap(m_testClassesFromXml, false);
651663
final Set<Class<?>> classes = cim.getClasses();
652664
final List<ITestNGMethod> runMethods = Lists.newArrayList();
@@ -656,7 +668,7 @@ private void privateRunJUnit() {
656668
// The resolution process is not specified in the JVM spec with a specific implementation,
657669
// so it can be eager => failure
658670
workers.add(
659-
new IWorker<ITestNGMethod>() {
671+
new IWorker<>() {
660672
/** @see TestMethodWorker#getTimeOut() */
661673
@Override
662674
public long getTimeOut() {

testng-core/src/main/java/org/testng/junit/IJUnitTestRunner.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
import org.testng.internal.ITestResultNotifier;
1010
import org.testng.internal.Utils;
1111

12-
/** An abstraction interface over JUnit test runners. */
12+
/**
13+
* An abstraction interface over JUnit test runners.
14+
*
15+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
16+
*/
17+
@Deprecated
1318
public interface IJUnitTestRunner {
1419

1520
void setInvokedMethodListeners(Collection<IInvokedMethodListener> listener);

testng-core/src/main/java/org/testng/junit/JUnit3TestClass.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import junit.framework.Test;
44

5-
/** @author lukas */
5+
/**
6+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
7+
*/
8+
@Deprecated
69
public class JUnit3TestClass extends JUnitTestClass {
710

811
public JUnit3TestClass(Test test) {

testng-core/src/main/java/org/testng/junit/JUnit3TestMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import org.testng.internal.ConstructorOrMethod;
77
import org.testng.internal.Utils;
88

9+
/**
10+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
11+
*/
12+
@Deprecated
913
public class JUnit3TestMethod extends JUnitTestMethod {
1014

1115
public JUnit3TestMethod(ITestObjectFactory objectFactory, JUnitTestClass owner, Test test) {

testng-core/src/main/java/org/testng/junit/JUnit3TestRecognizer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import java.lang.reflect.Modifier;
55
import junit.framework.Test;
66

7-
/** @author lukas */
7+
/**
8+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
9+
*/
10+
@Deprecated
811
public class JUnit3TestRecognizer implements JUnitTestRecognizer {
912

1013
public JUnit3TestRecognizer() {}

testng-core/src/main/java/org/testng/junit/JUnit4ConfigurationMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.lang.reflect.Method;
44
import org.testng.internal.ConstructorOrMethod;
55

6+
/**
7+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
8+
*/
9+
@Deprecated
610
public class JUnit4ConfigurationMethod extends ConstructorOrMethod {
711

812
private final Class<?> declaringClass;

testng-core/src/main/java/org/testng/junit/JUnit4TestClass.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import org.junit.runner.Description;
44

5-
/** @author lukas */
5+
/**
6+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
7+
*/
8+
@Deprecated
69
public class JUnit4TestClass extends JUnitTestClass {
710

811
public JUnit4TestClass(Description test) {

testng-core/src/main/java/org/testng/junit/JUnit4TestMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import org.testng.internal.Utils;
88
import org.testng.log4testng.Logger;
99

10+
/**
11+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
12+
*/
13+
@Deprecated
1014
public class JUnit4TestMethod extends JUnitTestMethod {
1115

1216
private static final AtomicBoolean warnOnce = new AtomicBoolean(false);

testng-core/src/main/java/org/testng/junit/JUnit4TestRecognizer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import java.lang.reflect.Method;
55
import org.junit.runner.RunWith;
66

7-
/** @author lukas */
7+
/**
8+
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
9+
*/
10+
@Deprecated
811
public final class JUnit4TestRecognizer implements JUnitTestRecognizer {
912

1013
public JUnit4TestRecognizer() {}

0 commit comments

Comments
 (0)