Package org.testng
Class TestRunner
- java.lang.Object
-
- org.testng.TestRunner
-
- All Implemented Interfaces:
IAttributes
,ITestResultNotifier
,IThreadWorkerFactory<ITestNGMethod>
,ITestContext
public class TestRunner extends Object implements ITestContext, ITestResultNotifier, IThreadWorkerFactory<ITestNGMethod>
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, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners)
This constructor is used by testng-remote, any changes related to it please contact with testng-team.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, Map<Class<? extends IDataProviderListener>,IDataProviderListener> dataProviderListeners)
-
Method Summary
-
-
-
Constructor Detail
-
TestRunner
protected TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners, Comparator<ITestNGMethod> comparator, Map<Class<? extends IDataProviderListener>,IDataProviderListener> dataProviderListeners)
-
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)
This constructor is used by testng-remote, any changes related to it please contact with testng-team.
-
-
Method Detail
-
getInvoker
public IInvoker getInvoker()
-
getBeforeSuiteMethods
public ITestNGMethod[] getBeforeSuiteMethods()
-
getAfterSuiteMethods
public ITestNGMethod[] getAfterSuiteMethods()
-
getBeforeTestConfigurationMethods
public ITestNGMethod[] getBeforeTestConfigurationMethods()
-
getAfterTestConfigurationMethods
public ITestNGMethod[] getAfterTestConfigurationMethods()
-
getTestClasses
public Collection<ITestClass> getTestClasses()
-
setTestName
public void setTestName(String name)
-
setOutputDirectory
public void setOutputDirectory(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 List<IWorker<ITestNGMethod>> createWorkers(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 String getName()
Description copied from interface:ITestContext
The name of this test.- Specified by:
getName
in interfaceITestContext
-
getStartDate
public Date getStartDate()
Description copied from interface:ITestContext
When this test started running.- Specified by:
getStartDate
in interfaceITestContext
- Returns:
- Returns the startDate.
-
getEndDate
public Date getEndDate()
Description copied from interface:ITestContext
When this test stopped running.- 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 String[] getIncludedGroups()
- Specified by:
getIncludedGroups
in interfaceITestContext
- Returns:
- All the groups that are included for this test run.
-
getExcludedGroups
public String[] getExcludedGroups()
- Specified by:
getExcludedGroups
in interfaceITestContext
- Returns:
- All the groups that are excluded for this test run.
-
getOutputDirectory
public 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 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 Collection<ITestNGMethod> getExcludedMethods()
- Specified by:
getExcludedMethods
in interfaceITestContext
- Returns:
- All the methods that were not included in this test run.
-
getFailedConfigurations
public IResultMap getFailedConfigurations()
Description copied from interface:ITestContext
Retrieves information about the failed configuration method invocations.- Specified by:
getFailedConfigurations
in interfaceITestContext
- See Also:
ITestContext.getFailedConfigurations()
-
getPassedConfigurations
public IResultMap getPassedConfigurations()
Description copied from interface:ITestContext
Retrieves information about the successful configuration method invocations.- Specified by:
getPassedConfigurations
in interfaceITestContext
- See Also:
ITestContext.getPassedConfigurations()
-
getSkippedConfigurations
public IResultMap getSkippedConfigurations()
Description copied from interface:ITestContext
Retrieves information about the skipped configuration method invocations.- Specified by:
getSkippedConfigurations
in interfaceITestContext
- See Also:
ITestContext.getSkippedConfigurations()
-
addPassedTest
public void addPassedTest(ITestNGMethod tm, ITestResult tr)
- Specified by:
addPassedTest
in interfaceITestResultNotifier
-
getPassedTests
public Set<ITestResult> getPassedTests(ITestNGMethod tm)
- Specified by:
getPassedTests
in interfaceITestResultNotifier
-
getFailedTests
public Set<ITestResult> getFailedTests(ITestNGMethod tm)
- Specified by:
getFailedTests
in interfaceITestResultNotifier
-
getSkippedTests
public Set<ITestResult> getSkippedTests(ITestNGMethod tm)
- Specified by:
getSkippedTests
in interfaceITestResultNotifier
-
addSkippedTest
public void addSkippedTest(ITestNGMethod tm, ITestResult tr)
- Specified by:
addSkippedTest
in interfaceITestResultNotifier
-
addInvokedMethod
public void addInvokedMethod(InvokedMethod im)
- Specified by:
addInvokedMethod
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 List<ITestListener> getTestListeners()
- Specified by:
getTestListeners
in interfaceITestResultNotifier
-
getConfigurationListeners
public 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)
-
getInvokedMethods
public List<ITestNGMethod> getInvokedMethods()
-
getCurrentXmlTest
public XmlTest getCurrentXmlTest()
- Specified by:
getCurrentXmlTest
in interfaceITestContext
- Returns:
- the current XmlTest.
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttribute
in interfaceIAttributes
- Parameters:
name
- The name of the attribute to return
-
setAttribute
public void setAttribute(String name, Object value)
Description copied from interface:IAttributes
Set a custom attribute.- Specified by:
setAttribute
in interfaceIAttributes
-
getAttributeNames
public Set<String> getAttributeNames()
- Specified by:
getAttributeNames
in interfaceIAttributes
- Returns:
- all the attributes names.
-
removeAttribute
public Object removeAttribute(String name)
Description copied from interface:IAttributes
Remove the attribute- Specified by:
removeAttribute
in interfaceIAttributes
- Returns:
- the attribute value if found, null otherwise
-
getGuiceModules
public List<com.google.inject.Module> getGuiceModules(Class<? extends com.google.inject.Module> cls)
- Specified by:
getGuiceModules
in interfaceITestContext
-
getInjector
public com.google.inject.Injector getInjector(List<com.google.inject.Module> moduleInstances)
- Specified by:
getInjector
in interfaceITestContext
-
getInjector
public com.google.inject.Injector getInjector(IClass iClass)
- Specified by:
getInjector
in interfaceITestContext
-
addInjector
public void addInjector(List<com.google.inject.Module> moduleInstances, com.google.inject.Injector injector)
- Specified by:
addInjector
in interfaceITestContext
-
-