Package org.testng
Class SuiteRunner
- java.lang.Object
-
- org.testng.SuiteRunner
-
- All Implemented Interfaces:
IAttributes,IInvokedMethodListener,ISuite,ITestNGListener
public class SuiteRunner extends java.lang.Object implements ISuite, IInvokedMethodListener
SuiteRunneris responsible for running all the tests included in one suite. The test start is triggered byrun()method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSuiteRunner.DefaultTestRunnerFactoryThe default implementation ofITestRunnerFactory.private static classSuiteRunner.ProxyTestRunnerFactoryprivate classSuiteRunner.SuiteWorker
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<ITestNGMethod>allTestMethodsprivate IAttributesattributesprivate java.util.Map<java.lang.Class<? extends IClassListener>,IClassListener>classListenersprivate IConfigurationconfigurationprivate static java.lang.StringDEFAULT_OUTPUT_DIRprivate DataProviderHolderholderprivate java.util.Map<java.lang.Class<? extends IInvokedMethodListener>,IInvokedMethodListener>invokedMethodListenersprivate java.util.Collection<IInvokedMethod>invokedMethodsThe list of all the methods invoked during this runprivate java.util.Map<java.lang.Class<? extends ISuiteListener>,ISuiteListener>listenersprivate ITestObjectFactoryobjectFactoryprivate java.lang.StringoutputDirprivate com.google.inject.InjectorparentInjectorprivate java.lang.StringremoteHostprivate java.util.List<IReporter>reportersprivate java.lang.BooleanskipFailedInvocationCountsprivate java.util.Map<java.lang.String,ISuiteResult>suiteResultsprivate SuiteRunStatesuiteStateprivate java.util.List<ITestListener>testListenersprivate java.util.List<TestRunner>testRunnersprivate TestListenerAdaptertextReporterprivate ITestRunnerFactorytmpRunnerFactoryprivate booleanuseDefaultListenersprivate java.util.Set<IExecutionVisualiser>visualisersprivate XmlSuitexmlSuite
-
Constructor Summary
Constructors Modifier Constructor Description SuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.Comparator<ITestNGMethod> comparator)protectedSuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.List<IMethodInterceptor> methodInterceptors, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.Collection<ITestListener> testListeners, java.util.Collection<IClassListener> classListeners, DataProviderHolder holder, java.util.Comparator<ITestNGMethod> comparator)SuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, java.util.Comparator<ITestNGMethod> comparator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddConfigurationListener(IConfigurationListener listener)protected voidaddListener(ISuiteListener reporter)voidaddListener(ITestNGListener listener)private voidaddReporter(IReporter listener)private voidaddVisualiser(IExecutionVisualiser visualiser)voidafterInvocation(IInvokedMethod method, ITestResult testResult)voidbeforeInvocation(IInvokedMethod method, ITestResult testResult)private ITestRunnerFactorybuildRunnerFactory(java.util.Comparator<ITestNGMethod> comparator)java.util.List<IInvokedMethod>getAllInvokedMethods()java.util.List<ITestNGMethod>getAllMethods()IAnnotationFindergetAnnotationFinder()Returns the annotation finder for the given annotation type.java.lang.ObjectgetAttribute(java.lang.String name)java.util.Set<java.lang.String>getAttributeNames()java.util.Collection<IDataProviderListener>getDataProviderListeners()java.util.Collection<ITestNGMethod>getExcludedMethods()java.lang.StringgetGuiceStage()java.lang.StringgetHost()private java.util.Collection<ITestNGMethod>getIncludedOrExcludedMethods(boolean included)java.util.Map<java.lang.String,java.util.Collection<ITestNGMethod>>getMethodsByGroups()Retrieves the map of groups and their associated test methods.java.lang.StringgetName()IObjectFactorygetObjectFactory()IObjectFactory2getObjectFactory2()java.lang.StringgetOutputDirectory()java.lang.StringgetParallel()java.lang.StringgetParameter(java.lang.String parameterName)FIXME: should be removed?com.google.inject.InjectorgetParentInjector()java.lang.StringgetParentModule()java.util.List<IReporter>getReporters()java.util.Map<java.lang.String,ISuiteResult>getResults()SuiteRunStategetSuiteState()Retrieves the shared state for a suite.XmlSuitegetXmlSuite()private voidinit(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.List<IMethodInterceptor> methodInterceptors, java.util.Collection<IInvokedMethodListener> invokedMethodListener, java.util.Collection<ITestListener> testListeners, java.util.Collection<IClassListener> classListeners, DataProviderHolder attribs, java.util.Comparator<ITestNGMethod> comparator)private voidinvokeListeners(boolean start)static voidppp(java.lang.String s)private voidprivateRun()java.lang.ObjectremoveAttribute(java.lang.String name)Remove the attributevoidrun()Triggers the start of running tests included in the suite.private voidrunInParallelTestMode()Implement. private voidrunSequentially()private voidrunTest(TestRunner tr)voidsetAttribute(java.lang.String name, java.lang.Object value)Set a custom attribute.voidsetHost(java.lang.String host)voidsetObjectFactory(ITestObjectFactory objectFactory)private voidsetOutputDir(java.lang.String outputdir)voidsetParentInjector(com.google.inject.Injector injector)voidsetReportResults(boolean reportResults)voidsetSkipFailedInvocationCounts(java.lang.Boolean skipFailedInvocationCounts)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.testng.IInvokedMethodListener
afterInvocation, beforeInvocation
-
-
-
-
Field Detail
-
DEFAULT_OUTPUT_DIR
private static final java.lang.String DEFAULT_OUTPUT_DIR
- See Also:
- Constant Field Values
-
suiteResults
private final java.util.Map<java.lang.String,ISuiteResult> suiteResults
-
testRunners
private final java.util.List<TestRunner> testRunners
-
listeners
private final java.util.Map<java.lang.Class<? extends ISuiteListener>,ISuiteListener> listeners
-
textReporter
private final TestListenerAdapter textReporter
-
outputDir
private java.lang.String outputDir
-
xmlSuite
private XmlSuite xmlSuite
-
parentInjector
private com.google.inject.Injector parentInjector
-
testListeners
private final java.util.List<ITestListener> testListeners
-
classListeners
private final java.util.Map<java.lang.Class<? extends IClassListener>,IClassListener> classListeners
-
tmpRunnerFactory
private ITestRunnerFactory tmpRunnerFactory
-
holder
private final DataProviderHolder holder
-
useDefaultListeners
private boolean useDefaultListeners
-
remoteHost
private java.lang.String remoteHost
-
configuration
private IConfiguration configuration
-
objectFactory
private ITestObjectFactory objectFactory
-
skipFailedInvocationCounts
private java.lang.Boolean skipFailedInvocationCounts
-
reporters
private final java.util.List<IReporter> reporters
-
invokedMethodListeners
private java.util.Map<java.lang.Class<? extends IInvokedMethodListener>,IInvokedMethodListener> invokedMethodListeners
-
invokedMethods
private final java.util.Collection<IInvokedMethod> invokedMethods
The list of all the methods invoked during this run
-
allTestMethods
private final java.util.List<ITestNGMethod> allTestMethods
-
suiteState
private final SuiteRunState suiteState
-
attributes
private final IAttributes attributes
-
visualisers
private final java.util.Set<IExecutionVisualiser> visualisers
-
-
Constructor Detail
-
SuiteRunner
public SuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, java.util.Comparator<ITestNGMethod> comparator)
-
SuiteRunner
public SuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.Comparator<ITestNGMethod> comparator)
-
SuiteRunner
protected SuiteRunner(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.List<IMethodInterceptor> methodInterceptors, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.Collection<ITestListener> testListeners, java.util.Collection<IClassListener> classListeners, DataProviderHolder holder, java.util.Comparator<ITestNGMethod> comparator)
-
-
Method Detail
-
init
private void init(IConfiguration configuration, XmlSuite suite, java.lang.String outputDir, ITestRunnerFactory runnerFactory, boolean useDefaultListeners, java.util.List<IMethodInterceptor> methodInterceptors, java.util.Collection<IInvokedMethodListener> invokedMethodListener, java.util.Collection<ITestListener> testListeners, java.util.Collection<IClassListener> classListeners, DataProviderHolder attribs, java.util.Comparator<ITestNGMethod> comparator)
-
getXmlSuite
public XmlSuite getXmlSuite()
- Specified by:
getXmlSuitein interfaceISuite- Returns:
- The representation of the current XML suite file.
-
getName
public java.lang.String getName()
-
setObjectFactory
public void setObjectFactory(ITestObjectFactory objectFactory)
-
setReportResults
public void setReportResults(boolean reportResults)
-
invokeListeners
private void invokeListeners(boolean start)
-
setOutputDir
private void setOutputDir(java.lang.String outputdir)
-
buildRunnerFactory
private ITestRunnerFactory buildRunnerFactory(java.util.Comparator<ITestNGMethod> comparator)
-
getParallel
public java.lang.String getParallel()
- Specified by:
getParallelin interfaceISuite- Returns:
- true if the tests must be run in parallel.
-
getParentModule
public java.lang.String getParentModule()
- Specified by:
getParentModulein interfaceISuite
-
getGuiceStage
public java.lang.String getGuiceStage()
- Specified by:
getGuiceStagein interfaceISuite
-
getParentInjector
public com.google.inject.Injector getParentInjector()
- Specified by:
getParentInjectorin interfaceISuite
-
setParentInjector
public void setParentInjector(com.google.inject.Injector injector)
- Specified by:
setParentInjectorin interfaceISuite
-
run
public void run()
Description copied from interface:ISuiteTriggers the start of running tests included in the suite.
-
privateRun
private void privateRun()
-
addVisualiser
private void addVisualiser(IExecutionVisualiser visualiser)
-
addReporter
private void addReporter(IReporter listener)
-
addConfigurationListener
void addConfigurationListener(IConfigurationListener listener)
-
getReporters
public java.util.List<IReporter> getReporters()
-
getDataProviderListeners
public java.util.Collection<IDataProviderListener> getDataProviderListeners()
-
runSequentially
private void runSequentially()
-
runTest
private void runTest(TestRunner tr)
-
runInParallelTestMode
private void runInParallelTestMode()
Implement. Since this kind of parallelism happens at the suite level, we need a special code path to execute it. All the other parallelism strategies are implemented at the test level in TestRunner#createParallelWorkers (but since this method deals with just one <test> tag, it can't implement , which is why we're doing it here).
-
addListener
protected void addListener(ISuiteListener reporter)
- Parameters:
reporter- The ISuiteListener interested in reporting the result of the current suite.
-
addListener
public void addListener(ITestNGListener listener)
- Specified by:
addListenerin interfaceISuite
-
getOutputDirectory
public java.lang.String getOutputDirectory()
- Specified by:
getOutputDirectoryin interfaceISuite- Returns:
- The output directory used for the reports.
-
getResults
public java.util.Map<java.lang.String,ISuiteResult> getResults()
- Specified by:
getResultsin interfaceISuite- Returns:
- The results for this suite.
-
getParameter
public java.lang.String getParameter(java.lang.String parameterName)
FIXME: should be removed?- Specified by:
getParameterin interfaceISuite- Parameters:
parameterName- The name of the parameter- Returns:
- The value of this parameter, or null if none was specified.
- See Also:
ISuite.getParameter(java.lang.String)
-
getMethodsByGroups
public java.util.Map<java.lang.String,java.util.Collection<ITestNGMethod>> getMethodsByGroups()
Description copied from interface:ISuiteRetrieves the map of groups and their associated test methods.- Specified by:
getMethodsByGroupsin interfaceISuite- Returns:
- A map where the key is the group and the value is a list of methods used by this group.
- See Also:
ISuite.getMethodsByGroups()
-
getExcludedMethods
public java.util.Collection<ITestNGMethod> getExcludedMethods()
- Specified by:
getExcludedMethodsin interfaceISuite- Returns:
- All the methods that were not included in this test run.
- See Also:
ISuite.getExcludedMethods()
-
getIncludedOrExcludedMethods
private java.util.Collection<ITestNGMethod> getIncludedOrExcludedMethods(boolean included)
-
getObjectFactory
public IObjectFactory getObjectFactory()
- Specified by:
getObjectFactoryin interfaceISuite- Returns:
- The object factory used to create all test instances.
-
getObjectFactory2
public IObjectFactory2 getObjectFactory2()
- Specified by:
getObjectFactory2in interfaceISuite
-
getAnnotationFinder
public IAnnotationFinder getAnnotationFinder()
Returns the annotation finder for the given annotation type.- Specified by:
getAnnotationFinderin interfaceISuite- Returns:
- the annotation finder for the given annotation type.
-
ppp
public static void ppp(java.lang.String s)
-
setHost
public void setHost(java.lang.String host)
-
getHost
public java.lang.String getHost()
-
getSuiteState
public SuiteRunState getSuiteState()
Description copied from interface:ISuiteRetrieves the shared state for a suite.- Specified by:
getSuiteStatein interfaceISuite- Returns:
- the share state of the current suite.
- See Also:
ISuite.getSuiteState()
-
setSkipFailedInvocationCounts
public void setSkipFailedInvocationCounts(java.lang.Boolean skipFailedInvocationCounts)
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttributein interfaceIAttributes- Parameters:
name- The name of the attribute to return- Returns:
- The attribute
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)Description copied from interface:IAttributesSet a custom attribute.- Specified by:
setAttributein interfaceIAttributes- Parameters:
name- The attribute namevalue- The attribute value
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNamesin interfaceIAttributes- Returns:
- all the attributes names.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
Description copied from interface:IAttributesRemove the attribute- Specified by:
removeAttributein interfaceIAttributes- Parameters:
name- The attribute name- Returns:
- the attribute value if found, null otherwise
-
afterInvocation
public void afterInvocation(IInvokedMethod method, ITestResult testResult)
- Specified by:
afterInvocationin interfaceIInvokedMethodListener
-
beforeInvocation
public void beforeInvocation(IInvokedMethod method, ITestResult testResult)
- Specified by:
beforeInvocationin interfaceIInvokedMethodListener
-
getAllInvokedMethods
public java.util.List<IInvokedMethod> getAllInvokedMethods()
- Specified by:
getAllInvokedMethodsin interfaceISuite- Returns:
- a list of all the methods that were invoked in this suite.
-
getAllMethods
public java.util.List<ITestNGMethod> getAllMethods()
- Specified by:
getAllMethodsin interfaceISuite- Returns:
- the total number of methods found in this suite. The presence of factories or data providers might cause the actual number of test methods run be bigger than this list.
-
-