Package org.testng
Class TestRunner
- java.lang.Object
-
- org.testng.TestRunner
-
- All Implemented Interfaces:
IAttributes
,IConfigEavesdropper
,ITestResultNotifier
,ITestContext
,IThreadWorkerFactory<ITestNGMethod>
public class TestRunner extends java.lang.Object implements ITestContext, ITestResultNotifier, IThreadWorkerFactory<ITestNGMethod>, IConfigEavesdropper
This class takes care of running one Test.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TestRunner.PriorityWeight
-
Constructor Summary
Constructors Modifier Constructor Description TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners)
TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Comparator<ITestNGMethod> comparator)
protected
TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, java.lang.String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(java.util.List<com.google.inject.Module> moduleInstances, com.google.inject.Injector injector)
This method stands deprecated as of TestNG7.3.0
void
addListener(ITestNGListener listener)
void
addPassedTest(ITestNGMethod tm, ITestResult tr)
void
addSkippedTest(ITestNGMethod tm, ITestResult tr)
java.util.List<IWorker<ITestNGMethod>>
createWorkers(java.util.List<ITestNGMethod> methods)
Create a list of workers to run the methods passed in parameter.ITestNGMethod[]
getAfterSuiteMethods()
ITestNGMethod[]
getAfterTestConfigurationMethods()
java.util.List<com.google.inject.Module>
getAllGuiceModules()
This method stands deprecated as of TestNG7.3.0
ITestNGMethod[]
getAllTestMethods()
java.lang.Object
getAttribute(java.lang.String name)
java.util.Set<java.lang.String>
getAttributeNames()
ITestNGMethod[]
getBeforeSuiteMethods()
ITestNGMethod[]
getBeforeTestConfigurationMethods()
java.util.List<IConfigurationListener>
getConfigurationListeners()
IResultMap
getConfigurationsScheduledForInvocation()
XmlTest
getCurrentXmlTest()
java.util.Date
getEndDate()
java.lang.String[]
getExcludedGroups()
java.util.Collection<ITestNGMethod>
getExcludedMethods()
IResultMap
getFailedButWithinSuccessPercentageTests()
IResultMap
getFailedConfigurations()
IResultMap
getFailedTests()
java.util.Set<ITestResult>
getFailedTests(ITestNGMethod tm)
java.util.List<com.google.inject.Module>
getGuiceModules(java.lang.Class<? extends com.google.inject.Module> cls)
This method stands deprecated as of TestNG7.3.0
java.lang.String
getHost()
java.lang.String[]
getIncludedGroups()
com.google.inject.Injector
getInjector(java.util.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
IInjectorFactory
getInjectorFactory()
IInvoker
getInvoker()
java.lang.String
getName()
java.lang.String
getOutputDirectory()
IResultMap
getPassedConfigurations()
IResultMap
getPassedTests()
java.util.Set<ITestResult>
getPassedTests(ITestNGMethod tm)
IResultMap
getSkippedConfigurations()
IResultMap
getSkippedTests()
java.util.Set<ITestResult>
getSkippedTests(ITestNGMethod tm)
java.util.Date
getStartDate()
ISuite
getSuite()
XmlTest
getTest()
java.util.Collection<ITestClass>
getTestClasses()
java.util.List<ITestListener>
getTestListeners()
static int
getVerbose()
java.lang.Object
removeAttribute(java.lang.String name)
Remove the attributevoid
run()
The main entry method for TestRunner.void
setAttribute(java.lang.String name, java.lang.Object value)
Set a custom attribute.void
setOutputDirectory(java.lang.String od)
void
setTestName(java.lang.String name)
void
setVerbose(int n)
-
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
-
-
-
-
Constructor Detail
-
TestRunner
protected TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, java.lang.String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Comparator<ITestNGMethod> comparator, DataProviderHolder otherHolder)
-
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners, java.util.Comparator<ITestNGMethod> comparator)
-
TestRunner
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, java.util.Collection<IInvokedMethodListener> invokedMethodListeners, java.util.List<IClassListener> classListeners)
-
-
Method Detail
-
getInvoker
public IInvoker getInvoker()
-
getBeforeSuiteMethods
public ITestNGMethod[] getBeforeSuiteMethods()
-
getAfterSuiteMethods
public ITestNGMethod[] getAfterSuiteMethods()
-
getBeforeTestConfigurationMethods
public ITestNGMethod[] getBeforeTestConfigurationMethods()
-
getAfterTestConfigurationMethods
public ITestNGMethod[] getAfterTestConfigurationMethods()
-
getTestClasses
public java.util.Collection<ITestClass> getTestClasses()
-
setTestName
public void setTestName(java.lang.String name)
-
setOutputDirectory
public void setOutputDirectory(java.lang.String od)
-
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...
-
createWorkers
public java.util.List<IWorker<ITestNGMethod>> createWorkers(java.util.List<ITestNGMethod> methods)
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
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfaceITestContext
- Returns:
- The name of this test.
-
getStartDate
public java.util.Date getStartDate()
- Specified by:
getStartDate
in interfaceITestContext
- Returns:
- Returns the startDate.
-
getEndDate
public java.util.Date getEndDate()
- Specified by:
getEndDate
in interfaceITestContext
- Returns:
- Returns the endDate.
-
getPassedTests
public IResultMap getPassedTests()
- Specified by:
getPassedTests
in interfaceITestContext
- Returns:
- A list of all the tests that run successfully.
-
getSkippedTests
public IResultMap getSkippedTests()
- Specified by:
getSkippedTests
in interfaceITestContext
- Returns:
- A list of all the tests that were skipped
-
getFailedTests
public IResultMap getFailedTests()
- Specified by:
getFailedTests
in interfaceITestContext
- Returns:
- A map of all the tests that passed, indexed by their ITextMethor.
- See Also:
ITestNGMethod
-
getFailedButWithinSuccessPercentageTests
public IResultMap 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
public java.lang.String[] getIncludedGroups()
- Specified by:
getIncludedGroups
in interfaceITestContext
- Returns:
- All the groups that are included for this test run.
-
getExcludedGroups
public java.lang.String[] getExcludedGroups()
- Specified by:
getExcludedGroups
in interfaceITestContext
- Returns:
- All the groups that are excluded for this test run.
-
getOutputDirectory
public java.lang.String getOutputDirectory()
- Specified by:
getOutputDirectory
in interfaceITestContext
- Returns:
- Where the reports will be generated.
-
getSuite
public ISuite getSuite()
- Specified by:
getSuite
in interfaceITestContext
- Returns:
- Returns the suite.
-
getAllTestMethods
public ITestNGMethod[] getAllTestMethods()
- Specified by:
getAllTestMethods
in interfaceITestContext
- Returns:
- All the test methods that were run.
-
getHost
public java.lang.String 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
public java.util.Collection<ITestNGMethod> getExcludedMethods()
- Specified by:
getExcludedMethods
in interfaceITestContext
- Returns:
- All the methods that were not included in this test run.
-
getFailedConfigurations
public IResultMap getFailedConfigurations()
- Specified by:
getFailedConfigurations
in interfaceITestContext
- Returns:
- The information about the failed configuration method invocations.
- See Also:
ITestContext.getFailedConfigurations()
-
getConfigurationsScheduledForInvocation
public IResultMap getConfigurationsScheduledForInvocation()
- Specified by:
getConfigurationsScheduledForInvocation
in interfaceIConfigEavesdropper
-
getPassedConfigurations
public IResultMap getPassedConfigurations()
- Specified by:
getPassedConfigurations
in interfaceITestContext
- Returns:
- The information about the successful configuration method invocations.
- See Also:
ITestContext.getPassedConfigurations()
-
getSkippedConfigurations
public IResultMap getSkippedConfigurations()
- Specified by:
getSkippedConfigurations
in interfaceITestContext
- Returns:
- The information about the skipped configuration method invocations.
- See Also:
ITestContext.getSkippedConfigurations()
-
addPassedTest
public void addPassedTest(ITestNGMethod tm, ITestResult tr)
- Specified by:
addPassedTest
in interfaceITestResultNotifier
-
getPassedTests
public java.util.Set<ITestResult> getPassedTests(ITestNGMethod tm)
- Specified by:
getPassedTests
in interfaceITestResultNotifier
-
getFailedTests
public java.util.Set<ITestResult> getFailedTests(ITestNGMethod tm)
- Specified by:
getFailedTests
in interfaceITestResultNotifier
-
getSkippedTests
public java.util.Set<ITestResult> getSkippedTests(ITestNGMethod tm)
- Specified by:
getSkippedTests
in interfaceITestResultNotifier
-
addSkippedTest
public void addSkippedTest(ITestNGMethod tm, ITestResult tr)
- Specified by:
addSkippedTest
in interfaceITestResultNotifier
-
addFailedTest
public void addFailedTest(ITestNGMethod testMethod, ITestResult result)
- Specified by:
addFailedTest
in interfaceITestResultNotifier
-
addFailedButWithinSuccessPercentageTest
public void addFailedButWithinSuccessPercentageTest(ITestNGMethod testMethod, ITestResult result)
- Specified by:
addFailedButWithinSuccessPercentageTest
in interfaceITestResultNotifier
-
getTest
public XmlTest getTest()
- Specified by:
getTest
in interfaceITestResultNotifier
-
getTestListeners
public java.util.List<ITestListener> getTestListeners()
- Specified by:
getTestListeners
in interfaceITestResultNotifier
-
getConfigurationListeners
public java.util.List<IConfigurationListener> getConfigurationListeners()
- Specified by:
getConfigurationListeners
in interfaceITestResultNotifier
-
getVerbose
public static int getVerbose()
-
setVerbose
public void setVerbose(int n)
-
addListener
public void addListener(ITestNGListener listener)
-
getCurrentXmlTest
public XmlTest getCurrentXmlTest()
- Specified by:
getCurrentXmlTest
in interfaceITestContext
- Returns:
- the current XmlTest.
-
getAttribute
public java.lang.Object getAttribute(java.lang.String name)
- Specified by:
getAttribute
in 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:IAttributes
Set a custom attribute.- Specified by:
setAttribute
in interfaceIAttributes
- Parameters:
name
- The attribute namevalue
- The attribute value
-
getAttributeNames
public java.util.Set<java.lang.String> getAttributeNames()
- Specified by:
getAttributeNames
in interfaceIAttributes
- Returns:
- all the attributes names.
-
removeAttribute
public java.lang.Object removeAttribute(java.lang.String name)
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 java.util.List<com.google.inject.Module> getGuiceModules(java.lang.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
public java.util.List<com.google.inject.Module> 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
public com.google.inject.Injector getInjector(java.util.List<com.google.inject.Module> moduleInstances)
Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getInjector
in interfaceITestContext
-
getInjector
public com.google.inject.Injector getInjector(IClass iClass)
Description copied from interface:ITestContext
This method stands deprecated as of TestNG7.3.0
- Specified by:
getInjector
in interfaceITestContext
-
addInjector
public void addInjector(java.util.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
-
getInjectorFactory
public IInjectorFactory getInjectorFactory()
- Specified by:
getInjectorFactory
in interfaceITestContext
-
-