diff --git a/.gitignore b/.gitignore
index ba30d93ade..633cd374f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@ z_build
.kobalt
.DS_Store
+.vscode/
\ No newline at end of file
diff --git a/CHANGES.txt b/CHANGES.txt
index b0a92c8661..ecddbdf51e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,13 @@
Current
+By EasonYi: feature/6.14.3/can-use-one-test-class-or-method-many-times-in-one-xml-test-case
+New: Allow the same method in one class for more than one time
+New: Allow the same class in one test for more than one time
+New: Upgrade to Java 8
+Fixed: Adjust the default parallel mode of SuiteRunner to TESTS
+Fixed: Wrong implementation about parameters overriding
+Notice: Since a lot of things have been changed, but only XML style was tested, that is JUnit and others are NOT tested by now, and you can find the tests in src/test/java/test/duplicate directory
+
+6.14.3
Fixed: GITHUB-1077: TestNG cannot handle load (Aheiss)
Fixed: GITHUB-1081: group-by-instances with test dependencies causes instantiation of tests to exponentially slow (Aheiss)
Fixed: GITHUB-1700: Test ignored if @BeforeMethod in base class fails for another test class (Krishnan Mahadevan)
diff --git a/build.gradle b/build.gradle
index e4d0fad408..0822ea9930 100644
--- a/build.gradle
+++ b/build.gradle
@@ -57,8 +57,8 @@ apply plugin: 'osgi'
apply plugin: 'version-injection'
apply plugin: 'eclipse'
-targetCompatibility = "1.7"
-sourceCompatibility = "1.7"
+targetCompatibility = "1.8"
+sourceCompatibility = "1.8"
eclipse {
classpath {
diff --git a/src/main/java/org/testng/IClass.java b/src/main/java/org/testng/IClass.java
index 1d213e8a39..3aba0795dc 100644
--- a/src/main/java/org/testng/IClass.java
+++ b/src/main/java/org/testng/IClass.java
@@ -12,7 +12,9 @@ public interface IClass {
* @return this test class name. This is the name of the
* corresponding Java class.
*/
- String getName();
+ default String getName() {
+ return getXmlClass().getName();
+ }
/**
* @return the <test> tag this class was found in.
@@ -24,15 +26,27 @@ public interface IClass {
*/
XmlClass getXmlClass();
+ default String getNameIndex() {
+ return getXmlClass().getNameIndex();
+ }
+
+ default int getIndex() {
+ return getXmlClass().getIndex();
+ }
+
/**
* If this class implements org.testng.ITest, returns its test name, otherwise returns null.
*/
- String getTestName();
+ default String getTestName() {
+ return getXmlTest().getName();
+ }
/**
* @return the Java class corresponding to this IClass.
*/
- Class> getRealClass();
+ default Class> getRealClass() {
+ return getXmlClass().getSupportClass();
+ }
/**
* Returns all the instances the methods will be invoked upon.
@@ -40,17 +54,16 @@ public interface IClass {
* of a @Factory annotation.
*
* @param create flag if a new set of instances must be returned
- * (if set to false)
+ * (if set to false)
* @return All the instances the methods will be invoked upon.
*/
Object[] getInstances(boolean create);
/**
- * @deprecated Not used
- *
* @return The number of instances used in this class. This method
* is needed for serialization since we don't know ahead of time if the
* instances of the test classes will be serializable.
+ * @deprecated Not used
*/
@Deprecated
int getInstanceCount();
diff --git a/src/main/java/org/testng/ITestClassFinder.java b/src/main/java/org/testng/ITestClassFinder.java
index 38448c60fc..6f7450de5c 100644
--- a/src/main/java/org/testng/ITestClassFinder.java
+++ b/src/main/java/org/testng/ITestClassFinder.java
@@ -1,5 +1,7 @@
package org.testng;
+import org.testng.xml.XmlClass;
+
/**
* This class is used by TestNG to locate the test classes.
*
@@ -19,6 +21,7 @@ public interface ITestClassFinder {
/**
* Return the IClass for a given class
*/
- IClass getIClass(Class> cls);
+// IClass getIClass(Class> cls);
+ IClass getIClass(XmlClass xmlClass);
}
diff --git a/src/main/java/org/testng/ITestMethodFinder.java b/src/main/java/org/testng/ITestMethodFinder.java
index 9cecd35804..5abdc0667f 100644
--- a/src/main/java/org/testng/ITestMethodFinder.java
+++ b/src/main/java/org/testng/ITestMethodFinder.java
@@ -1,10 +1,9 @@
package org.testng;
+import org.testng.xml.XmlClass;
import org.testng.xml.XmlTest;
-
-
/**
* This interface allows to modify the strategy used by TestRunner
* to find its test methods. At the time of this writing, TestNG
@@ -13,14 +12,19 @@
* methods that start with "test" or have a suite() method).
*
* @author Cedric Beust, May 3, 2004
- *
*/
public interface ITestMethodFinder {
/**
* @return All the applicable test methods.
*/
- ITestNGMethod[] getTestMethods(Class> cls, XmlTest xmlTest);
+ default ITestNGMethod[] getTestMethods(Class> cls, XmlTest xmlTest) {
+ return null;
+ }
+
+ default ITestNGMethod[] getTestMethods(XmlClass xmlClass, XmlTest xmlTest) {
+ return null;
+ }
/**
* @return All the methods that should be invoked
diff --git a/src/main/java/org/testng/ITestNGMethod.java b/src/main/java/org/testng/ITestNGMethod.java
index ec2a25c705..c606d0bcf7 100644
--- a/src/main/java/org/testng/ITestNGMethod.java
+++ b/src/main/java/org/testng/ITestNGMethod.java
@@ -1,273 +1,317 @@
-package org.testng;
-
-
-import org.testng.internal.ConstructorOrMethod;
-import org.testng.xml.XmlTest;
-
-import java.lang.reflect.Method;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-/**
- * Describes a TestNG annotated method and the instance on which it will be invoked.
- *
- * This interface is not meant to be implemented by users.
- */
-public interface ITestNGMethod extends Cloneable {
-
- /**
- * @return The real class on which this method was declared
- * (can be different from getMethod().getDeclaringClass() if
- * the test method was defined in a superclass).
- */
- Class getRealClass();
-
- ITestClass getTestClass();
-
- /**
- * Sets the test class having this method. This is not necessarily the declaring class.
- *
- * @param cls The test class having this method.
- */
- void setTestClass(ITestClass cls);
-
- /**
- * @return the corresponding Java test method.
- * @deprecated This method is deprecated and can now return null. Use
- * getConstructorOrMethod() instead.
- */
- @Deprecated
- Method getMethod();
-
- /**
- * Returns the method name. This is needed for serialization because
- * methods are not Serializable.
- * @return the method name.
- */
- String getMethodName();
-
- /**
- * @return All the instances the methods will be invoked upon.
- * This will typically be an array of one object in the absence
- * of an @Factory annotation.
- *
- * @deprecated Use getInstance().
- */
- @Deprecated
- Object[] getInstances();
-
- Object getInstance();
-
- /**
- * Needed for serialization.
- */
- long[] getInstanceHashCodes();
-
- /**
- * @return The groups this method belongs to, possibly added to the groups
- * declared on the class.
- */
- String[] getGroups();
-
- /**
- * @return The groups this method depends on, possibly added to the groups
- * declared on the class.
- */
- String[] getGroupsDependedUpon();
-
- /**
- * If a group was not found.
- */
- String getMissingGroup();
- void setMissingGroup(String group);
-
- /**
- * Before and After groups
- */
- String[] getBeforeGroups();
- String[] getAfterGroups();
-
- /**
- * @return The methods this method depends on, possibly added to the methods
- * declared on the class.
- */
- String[] getMethodsDependedUpon();
- void addMethodDependedUpon(String methodName);
-
- /**
- * @return true if this method was annotated with @Test
- */
- boolean isTest();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and beforeTestMethod = true
- */
- boolean isBeforeMethodConfiguration();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and beforeTestMethod = false
- */
- boolean isAfterMethodConfiguration();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and beforeClassMethod = true
- */
- boolean isBeforeClassConfiguration();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and beforeClassMethod = false
- */
- boolean isAfterClassConfiguration();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and beforeSuite = true
- */
- boolean isBeforeSuiteConfiguration();
-
- /**
- * @return true if this method was annotated with @Configuration
- * and afterSuite = true
- */
- boolean isAfterSuiteConfiguration();
-
- /**
- * @return true if this method is a @BeforeTest (@Configuration beforeTest=true)
- */
- boolean isBeforeTestConfiguration();
-
- /**
- * @return true if this method is an @AfterTest (@Configuration afterTest=true)
- */
- boolean isAfterTestConfiguration();
-
- boolean isBeforeGroupsConfiguration();
-
- boolean isAfterGroupsConfiguration();
-
- /**
- * @return The timeout in milliseconds.
- */
- long getTimeOut();
- void setTimeOut(long timeOut);
-
- /**
- * @return the number of times this method needs to be invoked.
- */
- int getInvocationCount();
- void setInvocationCount(int count);
-
- /**
- * @deprecated Will always return 0
- * @return 0
- */
- @Deprecated
- int getTotalInvocationCount();
-
- /**
- * @return the success percentage for this method (between 0 and 100).
- */
- int getSuccessPercentage();
-
- /**
- * @return The id of the thread this method was run in.
- */
- String getId();
-
- void setId(String id);
-
- long getDate();
-
- void setDate(long date);
-
- /**
- * Returns if this ITestNGMethod can be invoked from within IClass.
- */
- boolean canRunFromClass(IClass testClass);
-
- /**
- * @return true if this method is alwaysRun=true
- */
- boolean isAlwaysRun();
-
- /**
- * @return the number of threads to be used when invoking the method on parallel
- */
- int getThreadPoolSize();
-
- void setThreadPoolSize(int threadPoolSize);
-
- boolean getEnabled();
-
- String getDescription();
- void setDescription(String description);
-
- void incrementCurrentInvocationCount();
- int getCurrentInvocationCount();
- void setParameterInvocationCount(int n);
- int getParameterInvocationCount();
- void setMoreInvocationChecker(Callable moreInvocationChecker);
- boolean hasMoreInvocation();
-
- ITestNGMethod clone();
-
- IRetryAnalyzer getRetryAnalyzer();
- void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer);
-
- boolean skipFailedInvocations();
- void setSkipFailedInvocations(boolean skip);
-
- /**
- * The time under which all invocationCount methods need to complete by.
- */
- long getInvocationTimeOut();
-
- boolean ignoreMissingDependencies();
- void setIgnoreMissingDependencies(boolean ignore);
-
- /**
- * Which invocation numbers of this method should be used (only applicable
- * if it uses a data provider). If this value is an empty list, use all the values
- * returned from the data provider. These values are read from the XML file in
- * the tag.
- */
- List getInvocationNumbers();
- void setInvocationNumbers(List numbers);
-
- /**
- * The list of invocation numbers that failed, which is only applicable for
- * methods that have a data provider.
- */
- void addFailedInvocationNumber(int number);
- List getFailedInvocationNumbers();
-
- /**
- * The scheduling priority. Lower priorities get scheduled first.
- */
- int getPriority();
- void setPriority(int priority);
-
- /**
- * @return the XmlTest this method belongs to.
- */
- XmlTest getXmlTest();
-
- ConstructorOrMethod getConstructorOrMethod();
-
- /**
- * @return the parameters found in the include tag, if any
- * @param test
- */
- Map findMethodParameters(XmlTest test);
-
- /**
- * getRealClass().getName() + "." + getMethodName()
- * @return qualified name for this method
- */
- String getQualifiedName();
-}
+package org.testng;
+
+
+import org.testng.internal.ConstructorOrMethod;
+import org.testng.xml.XmlClass;
+import org.testng.xml.XmlInclude;
+import org.testng.xml.XmlTest;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+/**
+ * Describes a TestNG annotated method and the instance on which it will be invoked.
+ *
+ * This interface is not meant to be implemented by users.
+ */
+public interface ITestNGMethod extends Cloneable {
+
+ /**
+ * @return The real class on which this method was declared
+ * (can be different from getMethod().getDeclaringClass() if
+ * the test method was defined in a superclass).
+ */
+ Class getRealClass();
+
+ ITestClass getTestClass();
+
+ /**
+ * Sets the test class having this method. This is not necessarily the declaring class.
+ *
+ * @param cls The test class having this method.
+ */
+ void setTestClass(ITestClass cls);
+
+ XmlClass getXmlClass();
+
+ void setXmlClass(XmlClass m_xmlClass);
+
+ XmlInclude getXmlInclude();
+
+ void setXmlInclude(XmlInclude m_xmlInclude);
+
+ default int getClassIndex() {
+ return getTestClass().getIndex();
+ }
+
+ default String getClassNameIndex() {
+ return getXmlClass() == null ? "class_0" : getXmlClass().getNameIndex();
+ }
+
+ int getIndex();
+
+ String getNameIndex();
+
+ default String getKey() {
+ return getClassNameIndex() + "_" + getNameIndex();
+ }
+
+ /**
+ * @return the corresponding Java test method.
+ * @deprecated This method is deprecated and can now return null. Use
+ * getConstructorOrMethod() instead.
+ */
+ @Deprecated
+ Method getMethod();
+
+ /**
+ * Returns the method name. This is needed for serialization because
+ * methods are not Serializable.
+ *
+ * @return the method name.
+ */
+ String getMethodName();
+
+ /**
+ * @return All the instances the methods will be invoked upon.
+ * This will typically be an array of one object in the absence
+ * of an @Factory annotation.
+ * @deprecated Use getInstance().
+ */
+ @Deprecated
+ Object[] getInstances();
+
+ Object getInstance();
+
+ /**
+ * Needed for serialization.
+ */
+ long[] getInstanceHashCodes();
+
+ /**
+ * @return The groups this method belongs to, possibly added to the groups
+ * declared on the class.
+ */
+ String[] getGroups();
+
+ /**
+ * @return The groups this method depends on, possibly added to the groups
+ * declared on the class.
+ */
+ String[] getGroupsDependedUpon();
+
+ /**
+ * If a group was not found.
+ */
+ String getMissingGroup();
+
+ void setMissingGroup(String group);
+
+ /**
+ * Before and After groups
+ */
+ String[] getBeforeGroups();
+
+ String[] getAfterGroups();
+
+ /**
+ * @return The methods this method depends on, possibly added to the methods
+ * declared on the class.
+ */
+ String[] getMethodsDependedUpon();
+
+ void addMethodDependedUpon(String methodName);
+
+ /**
+ * @return true if this method was annotated with @Test
+ */
+ boolean isTest();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeTestMethod = true
+ */
+ boolean isBeforeMethodConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeTestMethod = false
+ */
+ boolean isAfterMethodConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeClassMethod = true
+ */
+ boolean isBeforeClassConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeClassMethod = false
+ */
+ boolean isAfterClassConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and beforeSuite = true
+ */
+ boolean isBeforeSuiteConfiguration();
+
+ /**
+ * @return true if this method was annotated with @Configuration
+ * and afterSuite = true
+ */
+ boolean isAfterSuiteConfiguration();
+
+ /**
+ * @return true if this method is a @BeforeTest (@Configuration beforeTest=true)
+ */
+ boolean isBeforeTestConfiguration();
+
+ /**
+ * @return true if this method is an @AfterTest (@Configuration afterTest=true)
+ */
+ boolean isAfterTestConfiguration();
+
+ boolean isBeforeGroupsConfiguration();
+
+ boolean isAfterGroupsConfiguration();
+
+ /**
+ * @return The timeout in milliseconds.
+ */
+ long getTimeOut();
+
+ void setTimeOut(long timeOut);
+
+ /**
+ * @return the number of times this method needs to be invoked.
+ */
+ int getInvocationCount();
+
+ void setInvocationCount(int count);
+
+ /**
+ * @return 0
+ * @deprecated Will always return 0
+ */
+ @Deprecated
+ int getTotalInvocationCount();
+
+ /**
+ * @return the success percentage for this method (between 0 and 100).
+ */
+ int getSuccessPercentage();
+
+ /**
+ * @return The id of the thread this method was run in.
+ */
+ String getId();
+
+ void setId(String id);
+
+ long getDate();
+
+ void setDate(long date);
+
+ /**
+ * Returns if this ITestNGMethod can be invoked from within IClass.
+ */
+ boolean canRunFromClass(IClass testClass);
+
+ /**
+ * @return true if this method is alwaysRun=true
+ */
+ boolean isAlwaysRun();
+
+ /**
+ * @return the number of threads to be used when invoking the method on parallel
+ */
+ int getThreadPoolSize();
+
+ void setThreadPoolSize(int threadPoolSize);
+
+ boolean getEnabled();
+
+ String getDescription();
+
+ void setDescription(String description);
+
+ void incrementCurrentInvocationCount();
+
+ int getCurrentInvocationCount();
+
+ int getParameterInvocationCount();
+
+ void setParameterInvocationCount(int n);
+
+ void setMoreInvocationChecker(Callable moreInvocationChecker);
+
+ boolean hasMoreInvocation();
+
+ ITestNGMethod clone();
+
+ IRetryAnalyzer getRetryAnalyzer();
+
+ void setRetryAnalyzer(IRetryAnalyzer retryAnalyzer);
+
+ boolean skipFailedInvocations();
+
+ void setSkipFailedInvocations(boolean skip);
+
+ /**
+ * The time under which all invocationCount methods need to complete by.
+ */
+ long getInvocationTimeOut();
+
+ boolean ignoreMissingDependencies();
+
+ void setIgnoreMissingDependencies(boolean ignore);
+
+ /**
+ * Which invocation numbers of this method should be used (only applicable
+ * if it uses a data provider). If this value is an empty list, use all the values
+ * returned from the data provider. These values are read from the XML file in
+ * the tag.
+ */
+ List getInvocationNumbers();
+
+ void setInvocationNumbers(List numbers);
+
+ /**
+ * The list of invocation numbers that failed, which is only applicable for
+ * methods that have a data provider.
+ */
+ void addFailedInvocationNumber(int number);
+
+ List getFailedInvocationNumbers();
+
+ /**
+ * The scheduling priority. Lower priorities get scheduled first.
+ */
+ int getPriority();
+
+ void setPriority(int priority);
+
+ /**
+ * @return the XmlTest this method belongs to.
+ */
+ XmlTest getXmlTest();
+
+ ConstructorOrMethod getConstructorOrMethod();
+
+ /**
+ * @param test
+ * @return the parameters found in the include tag, if any
+ */
+ Map findMethodParameters(XmlTest test);
+
+ /**
+ * getRealClass().getName() + "." + getMethodName()
+ *
+ * @return qualified name for this method
+ */
+ String getQualifiedName();
+}
diff --git a/src/main/java/org/testng/SuiteRunner.java b/src/main/java/org/testng/SuiteRunner.java
index 3550e54f8b..02857704f0 100644
--- a/src/main/java/org/testng/SuiteRunner.java
+++ b/src/main/java/org/testng/SuiteRunner.java
@@ -1,14 +1,9 @@
package org.testng;
-import static org.testng.internal.Utils.isStringBlank;
-
+import com.google.inject.Injector;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
-import org.testng.internal.Attributes;
-import org.testng.internal.IConfiguration;
-import org.testng.internal.IInvoker;
-import org.testng.internal.Systematiser;
-import org.testng.internal.Utils;
+import org.testng.internal.*;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.thread.ThreadUtil;
import org.testng.reporters.JUnitXMLReporter;
@@ -19,19 +14,10 @@
import java.io.File;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
-import com.google.inject.Injector;
+import static org.testng.internal.Utils.isStringBlank;
/**
* SuiteRunner is responsible for running all the tests included in one
@@ -40,63 +26,54 @@
public class SuiteRunner implements ISuite, IInvokedMethodListener {
private static final String DEFAULT_OUTPUT_DIR = "test-output";
-
+ private final Map, IClassListener> classListeners = Maps.newHashMap();
+ private final Map, IDataProviderListener> dataProviderListeners = Maps.newHashMap();
+ /**
+ * The list of all the methods invoked during this run
+ */
+ private final Collection invokedMethods = new ConcurrentLinkedQueue<>();
private Map suiteResults = Collections.synchronizedMap(Maps.newLinkedHashMap());
private List testRunners = Lists.newArrayList();
private Map, ISuiteListener> listeners = Maps.newHashMap();
private TestListenerAdapter textReporter = new TestListenerAdapter();
-
private String outputDir;
private XmlSuite xmlSuite;
private Injector parentInjector;
-
private List testListeners = Lists.newArrayList();
- private final Map, IClassListener> classListeners = Maps.newHashMap();
- private final Map, IDataProviderListener> dataProviderListeners = Maps.newHashMap();
private ITestRunnerFactory tmpRunnerFactory;
-
private boolean useDefaultListeners = true;
-
// The remote host where this suite was run, or null if run locally
private String remoteHost;
-
// The configuration
- private IConfiguration configuration;
-
+ private IConfiguration configuration;
private ITestObjectFactory objectFactory;
private Boolean skipFailedInvocationCounts = Boolean.FALSE;
private List reporters = Lists.newArrayList();
-
private Map, IInvokedMethodListener> invokedMethodListeners;
-
- /** The list of all the methods invoked during this run */
- private final Collection invokedMethods = new ConcurrentLinkedQueue<>();
-
private List allTestMethods = Lists.newArrayList();
private SuiteRunState suiteState = new SuiteRunState();
private IAttributes attributes = new Attributes();
public SuiteRunner(IConfiguration configuration, XmlSuite suite, String outputDir,
- Comparator comparator) {
+ Comparator comparator) {
this(configuration, suite, outputDir, null, comparator);
}
public SuiteRunner(IConfiguration configuration, XmlSuite suite, String outputDir,
- ITestRunnerFactory runnerFactory, Comparator comparator) {
+ ITestRunnerFactory runnerFactory, Comparator comparator) {
this(configuration, suite, outputDir, runnerFactory, false, comparator);
}
public SuiteRunner(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners, Comparator comparator)
- {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners, Comparator comparator) {
this(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- new ArrayList() /* method interceptor */,
- null /* invoked method listeners */,
- null /* test listeners */,
- null /* class listeners */, Collections., IDataProviderListener>emptyMap(), comparator);
+ new ArrayList() /* method interceptor */,
+ null /* invoked method listeners */,
+ null /* test listeners */,
+ null /* class listeners */, Collections., IDataProviderListener>emptyMap(), comparator);
}
@Deprecated
@@ -111,16 +88,15 @@ public SuiteRunner(IConfiguration configuration, XmlSuite suite, String outputDi
@Deprecated
public SuiteRunner(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners)
- {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners) {
this(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- new ArrayList() /* method interceptor */,
- null /* invoked method listeners */,
- null /* test listeners */,
- null /* class listeners */, Collections., IDataProviderListener>emptyMap(), Systematiser.getComparator());
+ new ArrayList() /* method interceptor */,
+ null /* invoked method listeners */,
+ null /* test listeners */,
+ null /* class listeners */, Collections., IDataProviderListener>emptyMap(), Systematiser.getComparator());
}
/**
@@ -130,36 +106,34 @@ public SuiteRunner(IConfiguration configuration,
//There are no external callers for this constructor but for TestNG. But since this method is a protected method
//we are following a proper deprecation strategy.
protected SuiteRunner(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners,
- List methodInterceptors,
- List invokedMethodListeners,
- List testListeners,
- List classListeners)
- {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners,
+ List methodInterceptors,
+ List invokedMethodListeners,
+ List testListeners,
+ List classListeners) {
init(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- methodInterceptors, invokedMethodListeners, testListeners, classListeners,
- Collections., IDataProviderListener>emptyMap(),
- Systematiser.getComparator());
+ methodInterceptors, invokedMethodListeners, testListeners, classListeners,
+ Collections., IDataProviderListener>emptyMap(),
+ Systematiser.getComparator());
}
@Deprecated
protected SuiteRunner(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners,
- List methodInterceptors,
- Collection invokedMethodListeners,
- Collection testListeners,
- Collection classListeners)
- {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners,
+ List methodInterceptors,
+ Collection invokedMethodListeners,
+ Collection testListeners,
+ Collection classListeners) {
init(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- methodInterceptors, invokedMethodListeners, testListeners, classListeners,
- Collections., IDataProviderListener>emptyMap(),
- Systematiser.getComparator());
+ methodInterceptors, invokedMethodListeners, testListeners, classListeners,
+ Collections., IDataProviderListener>emptyMap(),
+ Systematiser.getComparator());
}
/**
@@ -169,18 +143,17 @@ protected SuiteRunner(IConfiguration configuration,
//There are no external callers for this constructor but for TestNG. But since this method is a protected method
//we are following a proper deprecation strategy.
protected SuiteRunner(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners,
- List methodInterceptors,
- Collection invokedMethodListeners,
- Collection testListeners,
- Collection classListeners, Comparator comparator)
- {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners,
+ List methodInterceptors,
+ Collection invokedMethodListeners,
+ Collection testListeners,
+ Collection classListeners, Comparator comparator) {
this(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- methodInterceptors, invokedMethodListeners, testListeners, classListeners,
- Collections., IDataProviderListener>emptyMap(), comparator);
+ methodInterceptors, invokedMethodListeners, testListeners, classListeners,
+ Collections., IDataProviderListener>emptyMap(), comparator);
}
protected SuiteRunner(IConfiguration configuration,
@@ -193,32 +166,40 @@ protected SuiteRunner(IConfiguration configuration,
Collection testListeners,
Collection classListeners,
Map, IDataProviderListener> dataProviderListeners,
- Comparator comparator)
- {
+ Comparator comparator) {
init(configuration, suite, outputDir, runnerFactory, useDefaultListeners,
- methodInterceptors, invokedMethodListeners, testListeners, classListeners, dataProviderListeners, comparator);
+ methodInterceptors, invokedMethodListeners, testListeners, classListeners, dataProviderListeners, comparator);
}
private void init(IConfiguration configuration,
- XmlSuite suite,
- String outputDir,
- ITestRunnerFactory runnerFactory,
- boolean useDefaultListeners,
- List methodInterceptors,
- Collection invokedMethodListener,
- Collection testListeners,
- Collection classListeners,
- Map, IDataProviderListener> dataProviderListeners,
- Comparator comparator) {
+ XmlSuite suite,
+ String outputDir,
+ ITestRunnerFactory runnerFactory,
+ boolean useDefaultListeners,
+ List methodInterceptors,
+ Collection invokedMethodListener,
+ Collection testListeners,
+ Collection classListeners,
+ Map, IDataProviderListener> dataProviderListeners,
+ Comparator comparator) {
this.configuration = configuration;
+
+ // set default parallel mode to ParallelMode.TESTS
xmlSuite = suite;
+ if (xmlSuite.getParallel() == XmlSuite.ParallelMode.NONE) {
+ xmlSuite.setParallel(XmlSuite.ParallelMode.TESTS);
+ xmlSuite.getTests().stream()
+ .filter(xmlTest -> xmlTest.getParallel() == XmlSuite.ParallelMode.NONE)
+ .forEach(xmlTest -> xmlTest.setParallel(XmlSuite.ParallelMode.TESTS));
+ }
+
this.useDefaultListeners = useDefaultListeners;
tmpRunnerFactory = runnerFactory;
List localMethodInterceptors = methodInterceptors != null ? methodInterceptors : new
- ArrayList();
+ ArrayList();
setOutputDir(outputDir);
objectFactory = this.configuration.getObjectFactory();
- if(objectFactory == null) {
+ if (objectFactory == null) {
objectFactory = suite.getObjectFactory();
}
// Add our own IInvokedMethodListener
@@ -258,7 +239,7 @@ public int compare(XmlTest arg0, XmlTest arg1) {
for (XmlTest test : xmlTests) {
TestRunner tr = iTestRunnerFactory.newTestRunner(this, test, invokedMethodListeners.values(),
- Lists.newArrayList(this.classListeners.values()), this.dataProviderListeners);
+ Lists.newArrayList(this.classListeners.values()), this.dataProviderListeners);
//
// Install the method interceptor, if any was passed
@@ -287,10 +268,6 @@ public String getName() {
return xmlSuite.getName();
}
- public void setObjectFactory(ITestObjectFactory objectFactory) {
- this.objectFactory = objectFactory;
- }
-
public void setReportResults(boolean reportResults) {
useDefaultListeners = reportResults;
}
@@ -299,8 +276,7 @@ private void invokeListeners(boolean start) {
for (ISuiteListener sl : listeners.values()) {
if (start) {
sl.onStart(this);
- }
- else {
+ } else {
sl.onFinish(this);
}
}
@@ -312,7 +288,7 @@ private void setOutputDir(String outputdir) {
}
outputDir = (null != outputdir) ? new File(outputdir).getAbsolutePath()
- : null;
+ : null;
}
private ITestRunnerFactory2 buildRunnerFactory(Comparator comparator) {
@@ -320,13 +296,12 @@ private ITestRunnerFactory2 buildRunnerFactory(Comparator compara
if (null == tmpRunnerFactory) {
factory = new DefaultTestRunnerFactory(configuration,
- testListeners.toArray(new ITestListener[testListeners.size()]),
- useDefaultListeners, skipFailedInvocationCounts, comparator);
- }
- else {
+ testListeners.toArray(new ITestListener[testListeners.size()]),
+ useDefaultListeners, skipFailedInvocationCounts, comparator);
+ } else {
factory = new ProxyTestRunnerFactory(
- testListeners.toArray(new ITestListener[testListeners.size()]),
- tmpRunnerFactory);
+ testListeners.toArray(new ITestListener[testListeners.size()]),
+ tmpRunnerFactory);
}
return factory;
@@ -362,8 +337,7 @@ public void run() {
invokeListeners(true /* start */);
try {
privateRun();
- }
- finally {
+ } finally {
invokeListeners(false /* stop */);
}
}
@@ -371,13 +345,13 @@ public void run() {
private void privateRun() {
// Map for unicity, Linked for guaranteed order
- Map beforeSuiteMethods= new LinkedHashMap<>();
+ Map beforeSuiteMethods = new LinkedHashMap<>();
Map afterSuiteMethods = new LinkedHashMap<>();
IInvoker invoker = null;
// Get the invoker and find all the suite level methods
- for (TestRunner tr: testRunners) {
+ for (TestRunner tr : testRunners) {
// TODO: Code smell. Invoker should belong to SuiteRunner, not TestRunner
// -- cbeust
invoker = tr.getInvoker();
@@ -397,11 +371,11 @@ private void privateRun() {
// a tag and no real tests)
//
if (invoker != null) {
- if(! beforeSuiteMethods.values().isEmpty()) {
+ if (!beforeSuiteMethods.values().isEmpty()) {
invoker.invokeConfigurations(null,
- beforeSuiteMethods.values().toArray(new ITestNGMethod[beforeSuiteMethods.size()]),
- xmlSuite, xmlSuite.getParameters(), null, /* no parameter values */
- null /* instance */
+ beforeSuiteMethods.values().toArray(new ITestNGMethod[beforeSuiteMethods.size()]),
+ xmlSuite, xmlSuite.getParameters(), null, /* no parameter values */
+ null /* instance */
);
}
@@ -413,26 +387,24 @@ private void privateRun() {
boolean testsInParallel = XmlSuite.ParallelMode.TESTS.equals(xmlSuite.getParallel());
if (!testsInParallel) {
runSequentially();
- }
- else {
+ } else {
runInParallelTestMode();
}
//
// Invoke afterSuite methods
//
- if (! afterSuiteMethods.values().isEmpty()) {
+ if (!afterSuiteMethods.values().isEmpty()) {
invoker.invokeConfigurations(null,
- afterSuiteMethods.values().toArray(new ITestNGMethod[afterSuiteMethods.size()]),
- xmlSuite, xmlSuite.getAllParameters(), null, /* no parameter values */
+ afterSuiteMethods.values().toArray(new ITestNGMethod[afterSuiteMethods.size()]),
+ xmlSuite, xmlSuite.getAllParameters(), null, /* no parameter values */
- null /* instance */);
+ null /* instance */);
}
}
}
-
private void addReporter(IReporter listener) {
reporters.add(listener);
}
@@ -466,28 +438,13 @@ private void runTest(TestRunner tr) {
* tag, it can't implement , which is why we're doing it here).
*/
private void runInParallelTestMode() {
- List tasks= Lists.newArrayList(testRunners.size());
- for(TestRunner tr: testRunners) {
+ List tasks = Lists.newArrayList(testRunners.size());
+ for (TestRunner tr : testRunners) {
tasks.add(new SuiteWorker(tr));
}
ThreadUtil.execute("tests", tasks, xmlSuite.getThreadCount(),
- xmlSuite.getTimeOut(XmlTest.DEFAULT_TIMEOUT_MS), false);
- }
-
- private class SuiteWorker implements Runnable {
- private TestRunner testRunner;
-
- public SuiteWorker(TestRunner tr) {
- testRunner = tr;
- }
-
- @Override
- public void run() {
- Utils.log("[SuiteWorker]", 4, "Running XML Test '"
- + testRunner.getTest().getName() + "' in Parallel");
- runTest(testRunner);
- }
+ xmlSuite.getTimeOut(XmlTest.DEFAULT_TIMEOUT_MS), false);
}
/**
@@ -497,7 +454,7 @@ public void run() {
* @param reporter
*/
protected void addListener(ISuiteListener reporter) {
- if (! listeners.containsKey(reporter.getClass())) {
+ if (!listeners.containsKey(reporter.getClass())) {
listeners.put(reporter.getClass(), reporter);
}
}
@@ -519,7 +476,7 @@ public void addListener(ITestNGListener listener) {
}
if (listener instanceof IClassListener) {
IClassListener classListener = (IClassListener) listener;
- if (! classListeners.containsKey(classListener.getClass())) {
+ if (!classListeners.containsKey(classListener.getClass())) {
classListeners.put(classListener.getClass(), classListener);
}
}
@@ -587,7 +544,7 @@ public Collection getExcludedMethods() {
}
private Collection getIncludedOrExcludedMethods(boolean included) {
- List result= Lists.newArrayList();
+ List result = Lists.newArrayList();
for (TestRunner tr : testRunners) {
Collection methods = included ? tr.getInvokedMethods() : tr.getExcludedMethods();
@@ -604,6 +561,10 @@ public IObjectFactory getObjectFactory() {
return objectFactory instanceof IObjectFactory ? (IObjectFactory) objectFactory : null;
}
+ public void setObjectFactory(ITestObjectFactory objectFactory) {
+ this.objectFactory = objectFactory;
+ }
+
@Override
public IObjectFactory2 getObjectFactory2() {
return objectFactory instanceof IObjectFactory2 ? (IObjectFactory2) objectFactory : null;
@@ -611,6 +572,7 @@ public IObjectFactory2 getObjectFactory2() {
/**
* Returns the annotation finder for the given annotation type.
+ *
* @return the annotation finder for the given annotation type.
*/
@Override
@@ -618,25 +580,90 @@ public IAnnotationFinder getAnnotationFinder() {
return configuration.getAnnotationFinder();
}
- public static void ppp(String s) {
- System.out.println("[SuiteRunner] " + s);
+ @Override
+ public String getHost() {
+ return remoteHost;
+ }
+
+ public void setHost(String host) {
+ remoteHost = host;
+ }
+
+ /**
+ * @see org.testng.ISuite#getSuiteState()
+ */
+ @Override
+ public SuiteRunState getSuiteState() {
+ return suiteState;
+ }
+
+ public void setSkipFailedInvocationCounts(Boolean skipFailedInvocationCounts) {
+ if (skipFailedInvocationCounts != null) {
+ this.skipFailedInvocationCounts = skipFailedInvocationCounts;
+ }
+ }
+
+ @Override
+ public Object getAttribute(String name) {
+ return attributes.getAttribute(name);
+ }
+
+ @Override
+ public void setAttribute(String name, Object value) {
+ attributes.setAttribute(name, value);
+ }
+
+ @Override
+ public Set getAttributeNames() {
+ return attributes.getAttributeNames();
+ }
+
+ @Override
+ public Object removeAttribute(String name) {
+ return attributes.removeAttribute(name);
+ }
+
+ @Override
+ public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
+ //Empty implementation.
+ }
+
+ @Override
+ public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
+ if (method == null) {
+ throw new NullPointerException("Method should not be null");
+ }
+ invokedMethods.add(method);
+ }
+
+ @Override
+ public List getAllInvokedMethods() {
+ return new ArrayList<>(invokedMethods);
+ }
+
+ /////
+ // implements IInvokedMethodListener
+ //
+
+ @Override
+ public List getAllMethods() {
+ return allTestMethods;
}
/**
* The default implementation of {@link ITestRunnerFactory}.
*/
private static class DefaultTestRunnerFactory implements ITestRunnerFactory2 {
+ private final Comparator comparator;
private ITestListener[] failureGenerators;
private boolean useDefaultListeners;
private boolean skipFailedInvocationCounts;
private IConfiguration configuration;
- private final Comparator comparator;
public DefaultTestRunnerFactory(IConfiguration configuration,
- ITestListener[] failureListeners,
- boolean useDefaultListeners,
- boolean skipFailedInvocationCounts, Comparator comparator)
- {
+ ITestListener[] failureListeners,
+ boolean useDefaultListeners,
+ boolean skipFailedInvocationCounts, Comparator comparator) {
this.configuration = configuration;
failureGenerators = failureListeners;
this.useDefaultListeners = useDefaultListeners;
@@ -646,22 +673,22 @@ public DefaultTestRunnerFactory(IConfiguration configuration,
@Override
public TestRunner newTestRunner(ISuite suite, XmlTest test,
- Collection listeners, List classListeners) {
+ Collection listeners, List classListeners) {
return newTestRunner(suite, test, listeners, classListeners,
- Collections., IDataProviderListener>emptyMap());
+ Collections., IDataProviderListener>emptyMap());
}
@Override
public TestRunner newTestRunner(ISuite suite, XmlTest test,
- Collection listeners, List classListeners,
- Map, IDataProviderListener> dataProviderListeners) {
+ Collection listeners, List classListeners,
+ Map, IDataProviderListener> dataProviderListeners) {
boolean skip = skipFailedInvocationCounts;
- if (! skip) {
+ if (!skip) {
skip = test.skipFailedInvocationCounts();
}
TestRunner testRunner = new TestRunner(configuration, suite, test,
- suite.getOutputDirectory(), suite.getAnnotationFinder(), skip,
- listeners, classListeners, comparator, dataProviderListeners);
+ suite.getOutputDirectory(), suite.getAnnotationFinder(), skip,
+ listeners, classListeners, comparator, dataProviderListeners);
if (useDefaultListeners) {
testRunner.addListener(new TestHTMLReporter());
@@ -686,6 +713,10 @@ public TestRunner newTestRunner(ISuite suite, XmlTest test,
}
}
+ //
+ // implements IInvokedMethodListener
+ /////
+
private static class ProxyTestRunnerFactory implements ITestRunnerFactory2 {
private ITestListener[] failureGenerators;
private ITestRunnerFactory target;
@@ -697,18 +728,18 @@ public ProxyTestRunnerFactory(ITestListener[] failureListeners, ITestRunnerFacto
@Override
public TestRunner newTestRunner(ISuite suite, XmlTest test,
- Collection listeners, List classListeners) {
+ Collection listeners, List classListeners) {
return newTestRunner(suite, test, listeners, classListeners,
- Collections., IDataProviderListener>emptyMap());
+ Collections., IDataProviderListener>emptyMap());
}
@Override
public TestRunner newTestRunner(ISuite suite, XmlTest test,
Collection listeners, List classListeners,
- Map,IDataProviderListener> dataProviderListeners) {
+ Map, IDataProviderListener> dataProviderListeners) {
TestRunner testRunner;
if (target instanceof ITestRunnerFactory2) {
- testRunner = ((ITestRunnerFactory2)target).newTestRunner(suite, test, listeners, classListeners, dataProviderListeners);
+ testRunner = ((ITestRunnerFactory2) target).newTestRunner(suite, test, listeners, classListeners, dataProviderListeners);
} else {
testRunner = target.newTestRunner(suite, test, listeners, classListeners);
}
@@ -723,81 +754,18 @@ public TestRunner newTestRunner(ISuite suite, XmlTest test,
}
}
- public void setHost(String host) {
- remoteHost = host;
- }
-
- @Override
- public String getHost() {
- return remoteHost;
- }
-
-
-
- /**
- * @see org.testng.ISuite#getSuiteState()
- */
- @Override
- public SuiteRunState getSuiteState() {
- return suiteState;
- }
+ private class SuiteWorker implements Runnable {
+ private TestRunner testRunner;
- public void setSkipFailedInvocationCounts(Boolean skipFailedInvocationCounts) {
- if (skipFailedInvocationCounts != null) {
- this.skipFailedInvocationCounts = skipFailedInvocationCounts;
+ public SuiteWorker(TestRunner tr) {
+ testRunner = tr;
}
- }
-
-
-
- @Override
- public Object getAttribute(String name) {
- return attributes.getAttribute(name);
- }
-
- @Override
- public void setAttribute(String name, Object value) {
- attributes.setAttribute(name, value);
- }
-
- @Override
- public Set getAttributeNames() {
- return attributes.getAttributeNames();
- }
-
- @Override
- public Object removeAttribute(String name) {
- return attributes.removeAttribute(name);
- }
-
- /////
- // implements IInvokedMethodListener
- //
-
- @Override
- public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
- //Empty implementation.
- }
- @Override
- public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
- if (method == null) {
- throw new NullPointerException("Method should not be null");
+ @Override
+ public void run() {
+ Utils.log("[SuiteWorker]", 4, "Running XML Test '"
+ + testRunner.getTest().getName() + "' in Parallel");
+ runTest(testRunner);
}
- invokedMethods.add(method);
- }
-
- //
- // implements IInvokedMethodListener
- /////
-
- @Override
- public List getAllInvokedMethods() {
- return new ArrayList<>(invokedMethods);
- }
-
- @Override
- public List getAllMethods() {
- return allTestMethods;
}
}
diff --git a/src/main/java/org/testng/TestClass.java b/src/main/java/org/testng/TestClass.java
index bdf7f6d0d3..9d02898d8a 100644
--- a/src/main/java/org/testng/TestClass.java
+++ b/src/main/java/org/testng/TestClass.java
@@ -16,20 +16,18 @@
* - The configuration methods (test and method)
* - The class file
*/
-class TestClass extends NoOpTestClass implements ITestClass {
+public class TestClass extends NoOpTestClass implements ITestClass {
- private IAnnotationFinder annotationFinder = null;
+ private static final Logger LOG = Logger.getLogger(TestClass.class);
+ private IAnnotationFinder annotationFinder = null;
// The Strategy used to locate test methods (TestNG, JUnit, etc...)
private ITestMethodFinder testMethodFinder = null;
-
private IClass iClass = null;
private String testName;
private XmlTest xmlTest;
private XmlClass xmlClass;
- private static final Logger LOG =Logger.getLogger(TestClass.class);
-
- protected TestClass(IClass cls,
+ public TestClass(IClass cls,
ITestMethodFinder testMethodFinder,
IAnnotationFinder annotationFinder,
RunInfo runInfo,
@@ -61,8 +59,7 @@ private void init(IClass cls,
ITestMethodFinder testMethodFinder,
IAnnotationFinder annotationFinder,
XmlTest xmlTest,
- XmlClass xmlClass)
- {
+ XmlClass xmlClass) {
log(3, "Creating TestClass for " + cls);
iClass = cls;
m_testClass = cls.getRealClass();
@@ -112,60 +109,61 @@ public void addInstance(Object instance) {
}
private void initMethods() {
- ITestNGMethod[] methods = testMethodFinder.getTestMethods(m_testClass, xmlTest);
+// ITestNGMethod[] methods = testMethodFinder.getTestMethods(m_testClass, xmlTest);
+ ITestNGMethod[] methods = testMethodFinder.getTestMethods(xmlClass, xmlTest);
m_testMethods = createTestMethods(methods);
for (Object instance : iClass.getInstances(false)) {
m_beforeSuiteMethods = ConfigurationMethod
- .createSuiteConfigurationMethods(testMethodFinder.getBeforeSuiteMethods(m_testClass),
- annotationFinder,
- true,
- instance);
+ .createSuiteConfigurationMethods(testMethodFinder.getBeforeSuiteMethods(m_testClass),
+ annotationFinder,
+ true,
+ instance);
m_afterSuiteMethods = ConfigurationMethod
- .createSuiteConfigurationMethods(testMethodFinder.getAfterSuiteMethods(m_testClass),
- annotationFinder,
- false,
- instance);
+ .createSuiteConfigurationMethods(testMethodFinder.getAfterSuiteMethods(m_testClass),
+ annotationFinder,
+ false,
+ instance);
m_beforeTestConfMethods = ConfigurationMethod
- .createTestConfigurationMethods(testMethodFinder.getBeforeTestConfigurationMethods(m_testClass),
- annotationFinder,
- true,
- instance);
+ .createTestConfigurationMethods(testMethodFinder.getBeforeTestConfigurationMethods(m_testClass),
+ annotationFinder,
+ true,
+ instance);
m_afterTestConfMethods = ConfigurationMethod
- .createTestConfigurationMethods(testMethodFinder.getAfterTestConfigurationMethods(m_testClass),
- annotationFinder,
- false,
- instance);
+ .createTestConfigurationMethods(testMethodFinder.getAfterTestConfigurationMethods(m_testClass),
+ annotationFinder,
+ false,
+ instance);
m_beforeClassMethods = ConfigurationMethod
- .createClassConfigurationMethods(testMethodFinder.getBeforeClassMethods(m_testClass),
- annotationFinder,
- true,
- instance);
+ .createClassConfigurationMethods(testMethodFinder.getBeforeClassMethods(m_testClass),
+ annotationFinder,
+ true,
+ instance);
m_afterClassMethods = ConfigurationMethod
- .createClassConfigurationMethods(testMethodFinder.getAfterClassMethods(m_testClass),
- annotationFinder,
- false,
- instance);
+ .createClassConfigurationMethods(testMethodFinder.getAfterClassMethods(m_testClass),
+ annotationFinder,
+ false,
+ instance);
m_beforeGroupsMethods = ConfigurationMethod
- .createBeforeConfigurationMethods(testMethodFinder.getBeforeGroupsConfigurationMethods(m_testClass),
- annotationFinder,
- true,
- instance);
+ .createBeforeConfigurationMethods(testMethodFinder.getBeforeGroupsConfigurationMethods(m_testClass),
+ annotationFinder,
+ true,
+ instance);
m_afterGroupsMethods = ConfigurationMethod
- .createAfterConfigurationMethods(testMethodFinder.getAfterGroupsConfigurationMethods(m_testClass),
- annotationFinder,
- false,
- instance);
+ .createAfterConfigurationMethods(testMethodFinder.getAfterGroupsConfigurationMethods(m_testClass),
+ annotationFinder,
+ false,
+ instance);
m_beforeTestMethods = ConfigurationMethod
- .createTestMethodConfigurationMethods(testMethodFinder.getBeforeTestMethods(m_testClass),
- annotationFinder,
- true,
- instance);
+ .createTestMethodConfigurationMethods(testMethodFinder.getBeforeTestMethods(m_testClass),
+ annotationFinder,
+ true,
+ instance);
m_afterTestMethods = ConfigurationMethod
- .createTestMethodConfigurationMethods(testMethodFinder.getAfterTestMethods(m_testClass),
- annotationFinder,
- false,
- instance);
+ .createTestMethodConfigurationMethods(testMethodFinder.getAfterTestMethods(m_testClass),
+ annotationFinder,
+ false,
+ instance);
}
}
@@ -180,11 +178,11 @@ private ITestNGMethod[] createTestMethods(ITestNGMethod[] methods) {
if (m.getDeclaringClass().isAssignableFrom(m_testClass)) {
for (Object o : iClass.getInstances(false)) {
log(4, "Adding method " + tm + " on TestClass " + m_testClass);
- vResult.add(new TestNGMethod(/* tm.getRealClass(), */ m.getMethod(), annotationFinder, xmlTest,
- o));
+// vResult.add(new TestNGMethod(/* tm.getRealClass(), */ m.getMethod(), annotationFinder, xmlTest,
+ vResult.add(new TestNGMethod(m.getMethod(), annotationFinder, tm.getXmlInclude(), tm.getXmlClass(), xmlTest,
+ o));
}
- }
- else {
+ } else {
log(4, "Rejecting method " + tm + " for TestClass " + m_testClass);
}
}
@@ -223,8 +221,9 @@ protected void dump() {
@Override
public String toString() {
return Objects.toStringHelper(getClass())
- .add("name", m_testClass)
- .toString();
+ .add("name", m_testClass)
+ .add("index", getIndex())
+ .toString();
}
public IClass getIClass() {
diff --git a/src/main/java/org/testng/TestRunner.java b/src/main/java/org/testng/TestRunner.java
index 0dd7a7ff75..19ec808df7 100644
--- a/src/main/java/org/testng/TestRunner.java
+++ b/src/main/java/org/testng/TestRunner.java
@@ -1,48 +1,13 @@
package org.testng;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
+import com.google.inject.Injector;
+import com.google.inject.Module;
import org.testng.collections.ListMultiMap;
import org.testng.collections.Lists;
import org.testng.collections.Maps;
import org.testng.collections.Sets;
-import org.testng.internal.AbstractParallelWorker;
-import org.testng.internal.Attributes;
-import org.testng.internal.ClassHelper;
-import org.testng.internal.ClassInfoMap;
-import org.testng.internal.ConfigurationGroupMethods;
-import org.testng.internal.DefaultListenerFactory;
-import org.testng.internal.DynamicGraph;
+import org.testng.internal.*;
import org.testng.internal.DynamicGraph.Status;
-import org.testng.internal.DynamicGraphHelper;
-import org.testng.internal.GroupsHelper;
-import org.testng.internal.IConfiguration;
-import org.testng.internal.IInvoker;
-import org.testng.internal.ITestResultNotifier;
-import org.testng.internal.InvokedMethod;
-import org.testng.internal.Invoker;
-import org.testng.internal.MethodGroupsHelper;
-import org.testng.internal.MethodHelper;
-import org.testng.internal.ResultMap;
-import org.testng.internal.RunInfo;
-import org.testng.internal.Systematiser;
-import org.testng.internal.TestListenerHelper;
-import org.testng.internal.TestMethodWorker;
-import org.testng.internal.TestNGClassFinder;
-import org.testng.internal.TestNGMethodFinder;
-import org.testng.internal.Utils;
-import org.testng.internal.XmlMethodSelector;
import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.thread.graph.GraphThreadPoolExecutor;
import org.testng.internal.thread.graph.IThreadWorkerFactory;
@@ -54,8 +19,10 @@
import org.testng.xml.XmlPackage;
import org.testng.xml.XmlTest;
-import com.google.inject.Injector;
-import com.google.inject.Module;
+import java.util.*;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import static org.testng.internal.MethodHelper.fixMethodsWithClass;
@@ -63,54 +30,47 @@
* This class takes care of running one Test.
*/
public class TestRunner
- implements ITestContext, ITestResultNotifier, IThreadWorkerFactory {
+ implements ITestContext, ITestResultNotifier, IThreadWorkerFactory {
private static final String DEFAULT_PROP_OUTPUT_DIR = "test-output";
-
+ private static int m_verbose = 1;
private final Comparator comparator;
+ private final GuiceHelper guiceHelper = new GuiceHelper(this);
+ private final Map, IClassListener> m_classListeners = Maps.newHashMap();
+ private final Map, IDataProviderListener> m_dataProviderListeners;
+ private final Collection m_invokedMethods = new ConcurrentLinkedQueue<>();
private ISuite m_suite;
private XmlTest m_xmlTest;
private String m_testName;
-
- private final GuiceHelper guiceHelper = new GuiceHelper(this);
-
- private List m_testClassesFromXml= null;
-
- private IInvoker m_invoker= null;
- private IAnnotationFinder m_annotationFinder= null;
-
- /** ITestListeners support. */
+ private List m_testClassesFromXml = null;
+ private IInvoker m_invoker = null;
+ private IAnnotationFinder m_annotationFinder = null;
+ /**
+ * ITestListeners support.
+ */
private List m_testListeners = Lists.newArrayList();
private Set m_configurationListeners = Sets.newHashSet();
+ private IConfigurationListener m_confListener = new ConfigurationListener();
- private IConfigurationListener m_confListener= new ConfigurationListener();
-
+ // Information about this test run
private Collection m_invokedMethodListeners = Lists.newArrayList();
- private final Map, IClassListener> m_classListeners = Maps.newHashMap();
- private final Map, IDataProviderListener> m_dataProviderListeners;
-
/**
* All the test methods we found, associated with their respective classes.
* Note that these test methods might belong to different classes.
* We pick which ones to run at runtime.
*/
private ITestNGMethod[] m_allTestMethods = new ITestNGMethod[0];
-
- // Information about this test run
-
private Date m_startDate = null;
private Date m_endDate = null;
-
- /** A map to keep track of Class <-> IClass. */
- private Map, ITestClass> m_classMap = Maps.newLinkedHashMap();
-
- /** Where the reports will be created. */
- private String m_outputDirectory= DEFAULT_PROP_OUTPUT_DIR;
-
- // The XML method selector (groups/methods included/excluded in XML)
- private XmlMethodSelector m_xmlMethodSelector = new XmlMethodSelector();
-
- private static int m_verbose = 1;
+ /**
+ * A map to keep track of Class <-> IClass.
+ */
+// private Map, ITestClass> m_classMap = Maps.newLinkedHashMap();
+ private Map m_classMap = Maps.newLinkedHashMap();
+ /**
+ * Where the reports will be created.
+ */
+ private String m_outputDirectory = DEFAULT_PROP_OUTPUT_DIR;
//
// These next fields contain all the configuration methods found on this class.
@@ -119,39 +79,39 @@ public class TestRunner
// only a subset of them are run: those that are enabled and belong on the same class as
// (or a parent of) the test class.
//
- /** */
+ // The XML method selector (groups/methods included/excluded in XML)
+ private XmlMethodSelector m_xmlMethodSelector = new XmlMethodSelector();
+ /**
+ *
+ */
private ITestNGMethod[] m_beforeSuiteMethods = {};
private ITestNGMethod[] m_afterSuiteMethods = {};
private ITestNGMethod[] m_beforeXmlTestMethods = {};
private ITestNGMethod[] m_afterXmlTestMethods = {};
private List m_excludedMethods = Lists.newArrayList();
private ConfigurationGroupMethods m_groupMethods = null;
-
// Meta groups
private Map> m_metaGroups = Maps.newHashMap();
-
// All the tests that were run along with their result
private IResultMap m_passedTests = new ResultMap();
private IResultMap m_failedTests = new ResultMap();
private IResultMap m_failedButWithinSuccessPercentageTests = new ResultMap();
private IResultMap m_skippedTests = new ResultMap();
-
- private RunInfo m_runInfo= new RunInfo();
-
+ private RunInfo m_runInfo = new RunInfo();
// The host where this test was run, or null if run locally
private String m_host;
-
// Defined dynamically depending on
private List m_methodInterceptors;
-
private ClassMethodMap m_classMethodMap;
private TestNGClassFinder m_testClassFinder;
private IConfiguration m_configuration;
private IMethodInterceptor builtinInterceptor;
-
- public enum PriorityWeight {
- groupByInstance, preserveOrder, priority, dependsOnGroups, dependsOnMethods
- }
+ private IResultMap m_passedConfigurations = new ResultMap();
+ private IResultMap m_skippedConfigurations = new ResultMap();
+ private IResultMap m_failedConfigurations = new ResultMap();
+ private IAttributes m_attributes = new Attributes();
+ private ListMultiMap, Module> m_guiceModules = Maps.newListMultiMap();
+ private Map, Injector> m_injectors = Maps.newHashMap();
protected TestRunner(IConfiguration configuration,
ISuite suite,
@@ -161,37 +121,48 @@ protected TestRunner(IConfiguration configuration,
boolean skipFailedInvocationCounts,
Collection invokedMethodListeners,
List classListeners, Comparator comparator,
- Map, IDataProviderListener> dataProviderListeners) {
+ Map, IDataProviderListener> dataProviderListeners) {
this.comparator = comparator;
this.m_dataProviderListeners = Maps.newHashMap(dataProviderListeners);
init(configuration, suite, test, outputDirectory, finder, skipFailedInvocationCounts,
- invokedMethodListeners, classListeners);
+ invokedMethodListeners, classListeners);
}
-
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test,
- boolean skipFailedInvocationCounts,
- Collection invokedMethodListeners,
- List classListeners, Comparator comparator) {
+ boolean skipFailedInvocationCounts,
+ Collection invokedMethodListeners,
+ List classListeners, Comparator comparator) {
this.comparator = comparator;
this.m_dataProviderListeners = Collections.emptyMap();
init(configuration, suite, test, suite.getOutputDirectory(),
- suite.getAnnotationFinder(),
- skipFailedInvocationCounts, invokedMethodListeners, classListeners);
+ suite.getAnnotationFinder(),
+ skipFailedInvocationCounts, invokedMethodListeners, classListeners);
}
-
+
/**
* This constructor is used by testng-remote, any changes related to it please contact with testng-team.
*/
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test,
- boolean skipFailedInvocationCounts,
- Collection invokedMethodListeners,
- List classListeners) {
+ boolean skipFailedInvocationCounts,
+ Collection invokedMethodListeners,
+ List classListeners) {
this.comparator = Systematiser.getComparator();
this.m_dataProviderListeners = Collections.emptyMap();
init(configuration, suite, test, suite.getOutputDirectory(),
- suite.getAnnotationFinder(),
- skipFailedInvocationCounts, invokedMethodListeners, classListeners);
+ suite.getAnnotationFinder(),
+ skipFailedInvocationCounts, invokedMethodListeners, classListeners);
+ }
+
+ private static void log(int level, String s) {
+ Utils.log("TestRunner", level, s);
+ }
+
+ public static int getVerbose() {
+ return m_verbose;
+ }
+
+ public void setVerbose(int n) {
+ m_verbose = n;
}
private void init(IConfiguration configuration,
@@ -201,14 +172,13 @@ private void init(IConfiguration configuration,
IAnnotationFinder annotationFinder,
boolean skipFailedInvocationCounts,
Collection invokedMethodListeners,
- List classListeners)
- {
+ List classListeners) {
m_configuration = configuration;
- m_xmlTest= test;
+ m_xmlTest = test;
m_suite = suite;
m_testName = test.getName();
m_host = suite.getHost();
- m_testClassesFromXml= test.getXmlClasses();
+ m_testClassesFromXml = test.getXmlClasses();
setVerbose(test.getVerbose());
boolean preserveOrder = test.getPreserveOrder();
@@ -216,20 +186,20 @@ private void init(IConfiguration configuration,
builtinInterceptor = preserveOrder ? new PreserveOrderMethodInterceptor() : new InstanceOrderingMethodInterceptor();
List m_packageNamesFromXml = test.getXmlPackages();
- if(null != m_packageNamesFromXml) {
- for(XmlPackage xp: m_packageNamesFromXml) {
+ if (null != m_packageNamesFromXml) {
+ for (XmlPackage xp : m_packageNamesFromXml) {
m_testClassesFromXml.addAll(xp.getXmlClasses());
}
}
- m_annotationFinder= annotationFinder;
+ m_annotationFinder = annotationFinder;
m_invokedMethodListeners = invokedMethodListeners;
m_classListeners.clear();
for (IClassListener classListener : classListeners) {
m_classListeners.put(classListener.getClass(), classListener);
}
m_invoker = new Invoker(m_configuration, this, this, m_suite.getSuiteState(),
- skipFailedInvocationCounts, invokedMethodListeners, classListeners, m_dataProviderListeners.values());
+ skipFailedInvocationCounts, invokedMethodListeners, classListeners, m_dataProviderListeners.values());
if (test.getParallel() != null) {
log(3, "Running the tests in '" + test.getName() + "' with parallel mode:" + test.getParallel());
@@ -267,7 +237,7 @@ private void init() {
// Init methods and class map
// JUnit behavior is different and doesn't need this initialization step
- if(!m_xmlTest.isJUnit()) {
+ if (!m_xmlTest.isJUnit()) {
initMethods();
}
@@ -310,7 +280,7 @@ private void initListeners() {
// Instantiate all the listeners
for (Class extends ITestNGListener> c : listenerClasses) {
if (IClassListener.class.isAssignableFrom(c) && m_classListeners.containsKey(c)) {
- continue;
+ continue;
}
ITestNGListener listener = factory.createListener(c);
@@ -367,8 +337,9 @@ private void initMethods() {
List afterXmlTestMethods = Lists.newArrayList();
ClassInfoMap classMap = new ClassInfoMap(m_testClassesFromXml);
- m_testClassFinder= new TestNGClassFinder(classMap,Maps., List