org.testng
Class TestRunner

java.lang.Object
  extended by org.testng.TestRunner
All Implemented Interfaces:
java.io.Serializable, IAttributes, ITestContext

public class TestRunner
extends java.lang.Object
implements ITestContext

This class takes care of running one Test.

Author:
Cedric Beust, Apr 26, 2004, Alexandru Popescu
See Also:
Serialized Form

Field Summary
protected  XmlTest m_xmlTest
           
 
Constructor Summary
TestRunner(ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, java.util.List<IInvokedMethodListener> listeners)
           
TestRunner(ISuite suite, XmlTest test, IAnnotationFinder finder, boolean skipFailedInvocationCounts)
           
TestRunner(ISuite suite, XmlTest test, java.lang.String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, java.util.List<IInvokedMethodListener> invokedMethodListeners)
           
 
Method Summary
 void addConfigurationListener(IConfigurationListener icl)
           
 void addFailedButWithinSuccessPercentageTest(ITestNGMethod testMethod, ITestResult result)
           
 void addFailedTest(ITestNGMethod testMethod, ITestResult result)
           
 void addInvokedMethod(InvokedMethod im)
           
 void addListener(java.lang.Object listener)
           
 void addPassedTest(ITestNGMethod tm, ITestResult tr)
           
 void addSkippedTest(ITestNGMethod tm, ITestResult tr)
           
 void addTestListener(ITestListener il)
           
 java.util.List<IMethodWorker> createWorkers(XmlTest xmlTest, java.util.Set<ITestNGMethod> methods)
          Create a list of workers to run the methods passed in parameter.
 ITestNGMethod[] getAfterSuiteMethods()
           
 ITestNGMethod[] getAfterTestConfigurationMethods()
           
 ITestNGMethod[] getAllTestMethods()
           
 java.lang.Object getAttribute(java.lang.String name)
           
 ITestNGMethod[] getBeforeSuiteMethods()
           
 ITestNGMethod[] getBeforeTestConfigurationMethods()
           
 java.util.List<IConfigurationListener> getConfigurationListeners()
           
 XmlTest getCurrentXmlTest()
           
 java.util.Date getEndDate()
          When this test stopped running.
 java.lang.String[] getExcludedGroups()
           
 java.util.Collection<ITestNGMethod> getExcludedMethods()
           
 IResultMap getFailedButWithinSuccessPercentageTests()
           
 IResultMap getFailedConfigurations()
          Retrieves information about the failed configuration method invocations.
 IResultMap getFailedTests()
           
 java.lang.String getHost()
           
 java.util.Collection<ITestClass> getIClass()
           
 java.lang.String[] getIncludedGroups()
           
 java.util.List<ITestNGMethod> getInvokedMethods()
           
 IInvoker getInvoker()
           
 java.lang.String getName()
          The name of this test.
 java.lang.String getOutputDirectory()
           
 IResultMap getPassedConfigurations()
          Retrieves information about the successful configuration method invocations.
 IResultMap getPassedTests()
           
 java.util.Set<ITestResult> getPassedTests(ITestNGMethod tm)
           
 IResultMap getSkippedConfigurations()
          Retrieves information about the skipped configuration method invocations.
 IResultMap getSkippedTests()
           
 java.util.Date getStartDate()
          When this test started running.
 ISuite getSuite()
           
 XmlTest getTest()
           
 java.util.List<ITestListener> getTestListeners()
           
 TestPlan getTestPlan()
           
static int getVerbose()
           
 void privateRun(XmlTest xmlTest)
           
 void run()
          The main entry method for TestRunner.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Set a custom attribute.
 void setMethodInterceptor(IMethodInterceptor methodInterceptor)
           
 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
 

Field Detail

m_xmlTest

protected XmlTest m_xmlTest
Constructor Detail

TestRunner

public TestRunner(ISuite suite,
                  XmlTest test,
                  java.lang.String outputDirectory,
                  IAnnotationFinder finder,
                  boolean skipFailedInvocationCounts,
                  java.util.List<IInvokedMethodListener> invokedMethodListeners)

TestRunner

public TestRunner(ISuite suite,
                  XmlTest test,
                  IAnnotationFinder finder,
                  boolean skipFailedInvocationCounts)

TestRunner

public TestRunner(ISuite suite,
                  XmlTest test,
                  boolean skipFailedInvocationCounts,
                  java.util.List<IInvokedMethodListener> listeners)
Method Detail

getInvoker

public IInvoker getInvoker()

getBeforeSuiteMethods

public ITestNGMethod[] getBeforeSuiteMethods()

getAfterSuiteMethods

public ITestNGMethod[] getAfterSuiteMethods()

getBeforeTestConfigurationMethods

public ITestNGMethod[] getBeforeTestConfigurationMethods()

getAfterTestConfigurationMethods

public ITestNGMethod[] getAfterTestConfigurationMethods()

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface IAttributes
Parameters:
name - The name of the attribute to return

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 interface IAttributes

getIClass

public java.util.Collection<ITestClass> getIClass()

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...


privateRun

public void privateRun(XmlTest xmlTest)

createWorkers

public java.util.List<IMethodWorker> createWorkers(XmlTest xmlTest,
                                                   java.util.Set<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.


getTestPlan

public TestPlan getTestPlan()

getName

public java.lang.String getName()
Description copied from interface: ITestContext
The name of this test.

Specified by:
getName in interface ITestContext

getStartDate

public java.util.Date getStartDate()
Description copied from interface: ITestContext
When this test started running.

Specified by:
getStartDate in interface ITestContext
Returns:
Returns the startDate.

getEndDate

public java.util.Date getEndDate()
Description copied from interface: ITestContext
When this test stopped running.

Specified by:
getEndDate in interface ITestContext
Returns:
Returns the endDate.

getPassedTests

public IResultMap getPassedTests()
Specified by:
getPassedTests in interface ITestContext
Returns:
A list of all the tests that run successfully.

getSkippedTests

public IResultMap getSkippedTests()
Specified by:
getSkippedTests in interface ITestContext
Returns:
A list of all the tests that were skipped

getFailedTests

public IResultMap getFailedTests()
Specified by:
getFailedTests in interface ITestContext
Returns:
A map of all the tests that passed, indexed by their ITextMethor.
See Also:
ITestNGMethod

getFailedButWithinSuccessPercentageTests

public IResultMap getFailedButWithinSuccessPercentageTests()
Specified by:
getFailedButWithinSuccessPercentageTests in interface ITestContext
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 interface ITestContext
Returns:
All the groups that are included for this test run.

getExcludedGroups

public java.lang.String[] getExcludedGroups()
Specified by:
getExcludedGroups in interface ITestContext
Returns:
All the groups that are excluded for this test run.

getOutputDirectory

public java.lang.String getOutputDirectory()
Specified by:
getOutputDirectory in interface ITestContext
Returns:
Where the reports will be generated.

getSuite

public ISuite getSuite()
Specified by:
getSuite in interface ITestContext
Returns:
Returns the suite.

getAllTestMethods

public ITestNGMethod[] getAllTestMethods()
Specified by:
getAllTestMethods in interface ITestContext
Returns:
All the test methods that were run.

getHost

public java.lang.String getHost()
Specified by:
getHost in interface ITestContext
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 interface ITestContext
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 interface ITestContext
Returns:
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 interface ITestContext
Returns:
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 interface ITestContext
Returns:
See Also:
ITestContext.getSkippedConfigurations()

addPassedTest

public void addPassedTest(ITestNGMethod tm,
                          ITestResult tr)

getPassedTests

public java.util.Set<ITestResult> getPassedTests(ITestNGMethod tm)

addSkippedTest

public void addSkippedTest(ITestNGMethod tm,
                           ITestResult tr)

addInvokedMethod

public void addInvokedMethod(InvokedMethod im)

addFailedTest

public void addFailedTest(ITestNGMethod testMethod,
                          ITestResult result)

addFailedButWithinSuccessPercentageTest

public void addFailedButWithinSuccessPercentageTest(ITestNGMethod testMethod,
                                                    ITestResult result)

getTest

public XmlTest getTest()

getTestListeners

public java.util.List<ITestListener> getTestListeners()

getConfigurationListeners

public java.util.List<IConfigurationListener> getConfigurationListeners()

getVerbose

public static int getVerbose()

setVerbose

public void setVerbose(int n)

addListener

public void addListener(java.lang.Object listener)

addTestListener

public void addTestListener(ITestListener il)

addConfigurationListener

public void addConfigurationListener(IConfigurationListener icl)

getInvokedMethods

public java.util.List<ITestNGMethod> getInvokedMethods()
Returns:

setMethodInterceptor

public void setMethodInterceptor(IMethodInterceptor methodInterceptor)

getCurrentXmlTest

public XmlTest getCurrentXmlTest()
Specified by:
getCurrentXmlTest in interface ITestContext
Returns:
the current XmlTest.