Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Deprecate support for running JUnit tests #2849

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Current
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)
Expand Down
14 changes: 13 additions & 1 deletion testng-core/src/main/java/org/testng/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Class<?>> classes = cim.getClasses();
final List<ITestNGMethod> runMethods = Lists.newArrayList();
Expand All @@ -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<ITestNGMethod>() {
new IWorker<>() {
/** @see TestMethodWorker#getTimeOut() */
@Override
public long getTimeOut() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public interface IJUnitTestRunner {

void setInvokedMethodListeners(Collection<IInvokedMethodListener> listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import junit.framework.Test;

/** @author lukas */
/**
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
*/
@Deprecated
public class JUnit3TestClass extends JUnitTestClass {

public JUnit3TestClass(Test test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnit3TestMethod extends JUnitTestMethod {

public JUnit3TestMethod(ITestObjectFactory objectFactory, JUnitTestClass owner, Test test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnit3TestRecognizer implements JUnitTestRecognizer {

public JUnit3TestRecognizer() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnit4ConfigurationMethod extends ConstructorOrMethod {

private final Class<?> declaringClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import org.junit.runner.Description;

/** @author lukas */
/**
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
*/
@Deprecated
public class JUnit4TestClass extends JUnitTestClass {

public JUnit4TestClass(Description test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnit4TestMethod extends JUnitTestMethod {

private static final AtomicBoolean warnOnce = new AtomicBoolean(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public final class JUnit4TestRecognizer implements JUnitTestRecognizer {

public JUnit4TestRecognizer() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnit4TestRunner implements IJUnitTestRunner {

private final ITestObjectFactory objectFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnitMethodFinder implements ITestMethodFinder {

private final ITestObjectFactory objectFactory;
Expand Down Expand Up @@ -119,7 +120,10 @@ public ITestNGMethod[] getAfterGroupsConfigurationMethods(Class<?> testClass) {
return new ITestNGMethod[0];
}
}

/**
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
*/
@Deprecated
interface INameFilter {
boolean accept(ConstructorOrMethod method);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public abstract class JUnitTestClass implements ITestClass {

private List<ITestNGMethod> m_testMethods = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public final class JUnitTestFinder {

private static final String JUNIT3_TEST = "junit.framework.Test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public abstract class JUnitTestMethod extends BaseTestMethod {

protected JUnitTestMethod(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.testng.junit;

/** @author lukas */
/**
* @deprecated - Support for running JUnit tests stands deprecated as of TestNG <code>7.6.2</code>
*/
@Deprecated
interface JUnitTestRecognizer {

boolean isTest(Class c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>7.6.2</code>
*/
@Deprecated
public class JUnitTestRunner implements TestListener, IJUnitTestRunner {
public static final String SUITE_METHODNAME = "suite";

Expand Down