Package org.testng
Class TestRunner
java.lang.Object
org.testng.TestRunner
- All Implemented Interfaces:
IAttributes
,IConfigEavesdropper
,ITestResultNotifier
,ITestContext
,IThreadWorkerFactory<ITestNGMethod>
public class TestRunner
extends Object
implements ITestContext, ITestResultNotifier, IThreadWorkerFactory<ITestNGMethod>, IConfigEavesdropper
This class takes care of running one Test.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Comparator<ITestNGMethod>
private static final String
private GuiceHelper
private final DataProviderHolder
private static final Logger
private ITestNGMethod[]
private ITestNGMethod[]
private ITestNGMethod[]
private IAnnotationFinder
private final IAttributes
private ITestNGMethod[]
private ITestNGMethod[]
private final Map<Class<? extends IClassListener>,
IClassListener> private final Map<Class<?>,
ITestClass> A map to keep track of Class <-> IClass.private ClassMethodMap
private final IResultMap
private IConfiguration
private final Set<IConfigurationListener>
private final IConfigurationListener
private Date
private final List<ITestNGMethod>
private final IResultMap
private final IResultMap
private final IResultMap
private ConfigurationGroupMethods
private final ListMultiMap<Class<? extends com.google.inject.Module>,
com.google.inject.Module> private String
private IInjectorFactory
private Collection<IInvokedMethodListener>
private IInvoker
private List<IMethodInterceptor>
private String
Where the reports will be created.private final IResultMap
private final IResultMap
private final RunInfo
private final IResultMap
private final IResultMap
private Date
private ISuite
private TestNGClassFinder
private final List<ITestListener>
ITestListeners support.private String
private static int
private final XmlMethodSelector
private XmlTest
private final IContainer<ITestNGMethod>
private final Set<IExecutionVisualiser>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionTestRunner
(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners) TestRunner
(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator) protected
TestRunner
(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder) -
Method Summary
Modifier and TypeMethodDescription(package private) void
void
addFailedButWithinSuccessPercentageTest
(ITestNGMethod testMethod, ITestResult result) void
addFailedTest
(ITestNGMethod testMethod, ITestResult result) void
addGuiceModule
(com.google.inject.Module module) This method stands deprecated as of TestNG7.3.0
void
addInjector
(List<com.google.inject.Module> moduleInstances, com.google.inject.Injector injector) This method stands deprecated as of TestNG7.3.0
void
addListener
(ITestNGListener listener) private void
addMetaGroup
(String name, List<String> groupNames) (package private) void
addMethodInterceptor
(IMethodInterceptor methodInterceptor) void
addPassedTest
(ITestNGMethod tm, ITestResult tr) void
addSkippedTest
(ITestNGMethod tm, ITestResult tr) (package private) void
addTestListener
(ITestListener listener) private void
afterRun()
private void
Before run preparements.private ITestNGMethod[]
createGroups
(List<String> groups) createWorkers
(List<ITestNGMethod> methods) Create a list of workers to run the methods passed in parameter.private void
private void
fireEvent
(boolean isStart) Trigger the start/finish event.private void
List<com.google.inject.Module>
This method stands deprecated as of TestNG7.3.0
private List<XmlPackage>
Returns all packages to use for the current test.getAttribute
(String name) String[]
List<com.google.inject.Module>
getGuiceModules
(Class<? extends com.google.inject.Module> cls) This method stands deprecated as of TestNG7.3.0
getHost()
String[]
com.google.inject.Injector
getInjector
(List<com.google.inject.Module> moduleInstances) This method stands deprecated as of TestNG7.3.0
com.google.inject.Injector
getInjector
(IClass iClass) This method stands deprecated as of TestNG7.3.0
getName()
getSuite()
getTest()
static int
private static boolean
hasNoGuiceAnnotations
(IClass iClass) private void
init()
private void
init
(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder annotationFinder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners) private void
private void
initMetaGroups
(XmlTest xmlTest) Initialize meta groupsprivate void
private void
initRunInfo
(XmlTest xmlTest) private ITestNGMethod[]
intercept
(ITestNGMethod[] methods) Apply the method interceptor (if applicable) to the list of methods.private void
invokeTestConfigurations
(ITestNGMethod[] testConfigurationMethods) private static void
private void
logFailedTest
(ITestResult tr, boolean withinSuccessPercentage) private void
logStart()
Logs the beginning of thebeforeRun()
.private static Comparator<ITestNGMethod>
newComparator
(boolean needPrioritySort) private static BlockingQueue<Runnable>
newQueue
(boolean needPrioritySort) private void
privateRun
(XmlTest xmlTest) Main method that create a graph of methods and then pass it to the graph executor to run them.private void
removeAttribute
(String name) Remove the attributevoid
run()
The main entry method for TestRunner.private void
runJUnitWorkers
(List<? extends IWorker<ITestNGMethod>> workers) void
setAttribute
(String name, Object value) Set a custom attribute.void
void
setTestName
(String name) void
setVerbose
(int n) private boolean
sortOnPriority
(ITestNGMethod[] interceptedOrder) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.testng.internal.ITestResultNotifier
addInvokedMethod
-
Field Details
-
DEFAULT_PROP_OUTPUT_DIR
- See Also:
-
LOGGER
-
comparator
-
m_suite
-
m_xmlTest
-
m_testName
-
m_injectorFactory
-
guiceHelper
-
m_testClassesFromXml
-
m_invoker
-
m_annotationFinder
-
m_testListeners
ITestListeners support. -
m_configurationListeners
-
visualisers
-
m_confListener
-
m_invokedMethodListeners
-
m_classListeners
-
holder
-
m_startDate
-
m_endDate
-
testMethodsContainer
-
m_classMap
A map to keep track of Class <-> IClass. -
m_outputDirectory
Where the reports will be created. -
m_xmlMethodSelector
-
m_verbose
private static int m_verbose -
m_beforeSuiteMethods
-
m_afterSuiteMethods
-
m_beforeXmlTestMethods
-
m_afterXmlTestMethods
-
m_excludedMethods
-
m_groupMethods
-
m_metaGroups
-
m_passedTests
-
m_failedTests
-
m_failedButWithinSuccessPercentageTests
-
m_skippedTests
-
m_runInfo
-
m_host
-
m_methodInterceptors
-
m_classMethodMap
-
m_testClassFinder
-
m_configuration
-
m_allJunitTestMethods
-
m_passedConfigurations
-
m_skippedConfigurations
-
m_failedConfigurations
-
m_configsToBeInvoked
-
m_attributes
-
m_guiceModules
private final ListMultiMap<Class<? extends com.google.inject.Module>,com.google.inject.Module> m_guiceModules -
m_injectors
-
-
Constructor Details
-
TestRunner
protected TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder) -
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator) -
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners)
-
-
Method Details
-
init
private void init(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder annotationFinder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners) -
getAllPackages
Returns all packages to use for the current test. This includes the test from the test suite. Never returns null. -
getInvoker
-
getBeforeSuiteMethods
-
getAfterSuiteMethods
-
getBeforeTestConfigurationMethods
-
getAfterTestConfigurationMethods
-
init
private void init() -
initListeners
private void initListeners() -
initMetaGroups
Initialize meta groups -
initRunInfo
-
initMethods
private void initMethods() -
computeAndGetAllTestMethods
-
getTestClasses
-
setTestName
-
setOutputDirectory
-
addMetaGroup
-
createGroups
-
run
public void run()The main entry method for TestRunner.This is where all the hard work is done: - Invoke configuration methods - Invoke test methods - Catch exceptions - Collect results - Invoke listeners - etc...
-
forgetHeavyReferencesIfNeeded
private void forgetHeavyReferencesIfNeeded() -
beforeRun
private void beforeRun()Before run preparements. -
invokeTestConfigurations
-
privateRunJUnit
private void privateRunJUnit() -
newComparator
-
sortOnPriority
-
newQueue
-
privateRun
Main method that create a graph of methods and then pass it to the graph executor to run them. -
intercept
Apply the method interceptor (if applicable) to the list of methods. -
createWorkers
Create a list of workers to run the methods passed in parameter. Each test method is run in its own worker except in the following cases: - The method belongs to a class that has @Test(sequential=true) - The parallel attribute is set to "classes" In both these cases, all the methods belonging to that class will then be put in the same worker in order to run in the same thread.- Specified by:
createWorkers
in interfaceIThreadWorkerFactory<ITestNGMethod>
- Parameters:
methods
- tasks that need to be executed- Returns:
- list of workers
-
runJUnitWorkers
-
afterRun
private void afterRun() -
logStart
private void logStart()Logs the beginning of thebeforeRun()
. -
fireEvent
private void fireEvent(boolean isStart) Trigger the start/finish event.- Parameters:
isStart
- true if the event is for start, false if the event is for finish
-
getName
- Specified by:
getName
in interfaceITestContext
- Returns:
- The name of this test.
-
getStartDate
- Specified by:
getStartDate
in interfaceITestContext
- Returns:
- Returns the startDate.
-
getEndDate
- Specified by:
getEndDate
in interfaceITestContext
- Returns:
- Returns the endDate.
-
getPassedTests
- Specified by:
getPassedTests
in interfaceITestContext
- Returns:
- A list of all the tests that run successfully.
-
getSkippedTests
- Specified by:
getSkippedTests
in interfaceITestContext
- Returns:
- A list of all the tests that were skipped
-
getFailedTests
- Specified by:
getFailedTests
in interfaceITestContext
- Returns:
- A map of all the tests that passed, indexed by their ITextMethor.
- See Also:
-
getFailedButWithinSuccessPercentageTests
- Specified by:
getFailedButWithinSuccessPercentageTests
in interfaceITestContext
- Returns:
- A list of all the tests that failed but are being ignored because annotated with a successPercentage.
-
getIncludedGroups
- Specified by:
getIncludedGroups
in interfaceITestContext
- Returns:
- All the groups that are included for this test run.
-
getExcludedGroups
- Specified by:
getExcludedGroups
in interfaceITestContext
- Returns:
- All the groups that are excluded for this test run.
-
getOutputDirectory
- Specified by:
getOutputDirectory
in interfaceITestContext
- Returns:
- Where the reports will be generated.
-
getSuite
- Specified by:
getSuite
in interfaceITestContext
- Returns:
- Returns the suite.
-
getAllTestMethods
- Specified by:
getAllTestMethods
in interfaceITestContext
- Returns:
- All the test methods that were run.
-
getHost
- Specified by:
getHost
in interfaceITestContext
- Returns:
- The host where this test was run, or null if it was run locally. The returned string has the form: host:port
-
getExcludedMethods
- Specified by:
getExcludedMethods
in interfaceITestContext
- Returns:
- All the methods that were not included in this test run.
-
getFailedConfigurations
- Specified by:
getFailedConfigurations
in interfaceITestContext
- Returns:
- The information about the failed configuration method invocations.
- See Also:
-
getConfigurationsScheduledForInvocation
- Specified by:
getConfigurationsScheduledForInvocation
in interfaceIConfigEavesdropper
-
getPassedConfigurations
- Specified by:
getPassedConfigurations
in interfaceITestContext
- Returns:
- The information about the successful configuration method invocations.
- See Also:
-
getSkippedConfigurations
- Specified by:
getSkippedConfigurations
in interfaceITestContext
- Returns:
- The information about the skipped configuration method invocations.
- See Also:
-
addPassedTest
- Specified by:
addPassedTest
in interfaceITestResultNotifier
-
getPassedTests
- Specified by:
getPassedTests
in interfaceITestResultNotifier
-
getFailedTests
- Specified by:
getFailedTests
in interfaceITestResultNotifier
-
getSkippedTests
- Specified by:
getSkippedTests
in interfaceITestResultNotifier
-
addSkippedTest
- Specified by:
addSkippedTest
in interfaceITestResultNotifier
-
addFailedTest
- Specified by:
addFailedTest
in interfaceITestResultNotifier
-
addFailedButWithinSuccessPercentageTest
- Specified by:
addFailedButWithinSuccessPercentageTest
in interfaceITestResultNotifier
-
getTest
- Specified by:
getTest
in interfaceITestResultNotifier
-
getTestListeners
- Specified by:
getTestListeners
in interfaceITestResultNotifier
-
getConfigurationListeners
- Specified by:
getConfigurationListeners
in interfaceITestResultNotifier
-
logFailedTest
-
log
-
getVerbose
public static int getVerbose() -
setVerbose
public void setVerbose(int n) -
addTestListener
-
addListener
-
addConfigurationListener
-
dumpInvokedMethods
private void dumpInvokedMethods() -
addMethodInterceptor
-
getCurrentXmlTest
- Specified by:
getCurrentXmlTest
in interfaceITestContext
- Returns:
- the current XmlTest.
-
getAttribute
- Specified by:
getAttribute
in interfaceIAttributes
- Parameters:
name
- The name of the attribute to return- Returns:
- The attribute
-
setAttribute
Description copied from interface:IAttributes
Set a custom attribute.- Specified by:
setAttribute
in interfaceIAttributes
- Parameters:
name
- The attribute namevalue
- The attribute value
-
getAttributeNames
- Specified by:
getAttributeNames
in interfaceIAttributes
- Returns:
- all the attributes names.
-
removeAttribute
Description copied from interface:IAttributes
Remove the attribute- Specified by:
removeAttribute
in interfaceIAttributes
- Parameters:
name
- The attribute name- Returns:
- the attribute value if found, null otherwise
-
getGuiceModules
public List<com.google.inject.Module> getGuiceModules(Class<? extends com.google.inject.Module> cls) Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getGuiceModules
in interfaceITestContext
-
getAllGuiceModules
Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getAllGuiceModules
in interfaceITestContext
-
addGuiceModule
public void addGuiceModule(com.google.inject.Module module) Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
addGuiceModule
in interfaceITestContext
-
getInjector
Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getInjector
in interfaceITestContext
-
getInjector
Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getInjector
in interfaceITestContext
-
addInjector
public void addInjector(List<com.google.inject.Module> moduleInstances, com.google.inject.Injector injector) Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
addInjector
in interfaceITestContext
-
hasNoGuiceAnnotations
-
getInjectorFactory
- Specified by:
getInjectorFactory
in interfaceITestContext
-