com.googlecode.lightest.core
Class LightestTestListener

java.lang.Object
  extended by org.testng.TestListenerAdapter
      extended by com.googlecode.lightest.core.LightestTestListener
All Implemented Interfaces:
ILightestTestListener, groovy.lang.GroovyObject, org.testng.internal.IConfigurationListener, org.testng.internal.IResultListener, IReporter, ISuiteListener, ITestListener, ITestNGListener

public class LightestTestListener
extends TestListenerAdapter
implements groovy.lang.GroovyObject, ILightestTestListener

This class is responsible for wiring task dispatchers to testcases, and recording the results of running tasks. It also notifies any registered reporters to generate reports at appropriate points in the test execution lifecycle. It supports two styles of reporters: ones that implement IReporter, and ones that implement ILightestReporter. The former is used to create a single report at the end of the suite run, while the latter may be updated throughout the run, as tests are completed.


Field Summary
static String ATTR_STRATEGY
           
 
Constructor Summary
LightestTestListener()
           
 
Method Summary
 void addEnvironmentMapping(Class testClass, ITestEnvironment env)
          Records the mapping between a test class and the environment in which the test was performed.
 void generateReport(List xmlSuites, List suites, String outputDirectory)
          Invokes generateReport() on all registered IReporter reporters.
 groovy.lang.MetaClass getMetaClass()
           
 String getOutputDir()
           
 Object getProperty(String name)
           
 TestRegistry getRegistry()
          Returns the registry of pending tests.
 Map getTaskResultMap()
           
 void initializeReporters(String configText)
          Invokes generateBaseReport() on all registered reporters that are instances of ILightestReporter.
 Object invokeMethod(String name, Object args)
           
 void onFinish(ISuite suite)
          Implemented to satisfy the ISuiteListener interface.
 void onFinish(ITestContext context)
          Ensures the list of failed tests maintained by the TestNG TestRunner implementation underlying the ITestContext reflects the actual test result status.
 void onStart(ISuite suite)
          Generates the base report for all registered ILightestReporter's .
 void onStart(ITestContext context)
           
 void onTaskComplete(ITaskResult taskResult, ITestResult testResult)
          Adds the ITaskResult to the list kept for each ITestResult.
 void onTestFailure(ITestResult result)
           
 void onTestFinish(ITestResult result)
          Records test run information, updates testng-results.xml, and invokes the report for all registered ILightestReporter's .
 void onTestSkipped(ITestResult result)
           
 void onTestStart(ITestResult result)
           
 void onTestSuccess(ITestResult result)
          Instead of simply delegating to the TestListenerAdapter, we first check if the tasks corresponding to the test method were all OK.
 void registerReporter(Object reporter)
          Registers a new reporter to be notified of reportable events.
protected  void resolveResult(ITestResult result)
          Resolves the result in the registry.
 void setDispatcherAssignmentStrategy(IDispatcherAssignmentStrategy strategy)
          This listener is the mechanism through which the dispatcher assignment strategy is communicated to each testcase.
 void setMetaClass(groovy.lang.MetaClass metaClass)
           
 void setOutputDir(String value)
          Sets the output directory to be propagated to all registered reporters.
 void setProperty(String name, Object value)
           
 void setRegistry(TestRegistry value)
          Sets the registry of pending tests, which are tests that will be run that have not yet been reported on.
 void setTaskResultMap(Map value)
           
 
Methods inherited from class org.testng.TestListenerAdapter
getAllTestMethods, getConfigurationFailures, getConfigurationSkips, getFailedButWithinSuccessPercentageTests, getFailedTests, getPassedTests, getSkippedTests, getTestContexts, onConfigurationFailure, onConfigurationSkip, onConfigurationSuccess, onTestFailedButWithinSuccessPercentage, setAllTestMethods, setFailedButWithinSuccessPercentageTests, setFailedTests, setPassedTests, setSkippedTests
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.testng.ITestListener
onTestFailedButWithinSuccessPercentage
 

Field Detail

ATTR_STRATEGY

public static final String ATTR_STRATEGY
Constructor Detail

LightestTestListener

public LightestTestListener()
Method Detail

getRegistry

public TestRegistry getRegistry()
Description copied from interface: ILightestTestListener
Returns the registry of pending tests.

Specified by:
getRegistry in interface ILightestTestListener

setRegistry

public void setRegistry(TestRegistry value)
Description copied from interface: ILightestTestListener
Sets the registry of pending tests, which are tests that will be run that have not yet been reported on. Tests will be removed from the registry once they are reported as being run.

Specified by:
setRegistry in interface ILightestTestListener

getOutputDir

public String getOutputDir()

setOutputDir

public void setOutputDir(String value)
Description copied from interface: ILightestTestListener
Sets the output directory to be propagated to all registered reporters.

Specified by:
setOutputDir in interface ILightestTestListener

getTaskResultMap

public Map getTaskResultMap()

setTaskResultMap

public void setTaskResultMap(Map value)

addEnvironmentMapping

public void addEnvironmentMapping(Class testClass,
                                  ITestEnvironment env)
Records the mapping between a test class and the environment in which the test was performed.

Specified by:
addEnvironmentMapping in interface ILightestTestListener
Parameters:
testClass -
env -

setDispatcherAssignmentStrategy

public void setDispatcherAssignmentStrategy(IDispatcherAssignmentStrategy strategy)
Description copied from interface: ILightestTestListener
This listener is the mechanism through which the dispatcher assignment strategy is communicated to each testcase. The strategy is set on the context object when onTestStart() is called. Thus, the strategy must be set on this listener prior to any tests being run.

Specified by:
setDispatcherAssignmentStrategy in interface ILightestTestListener

onFinish

public void onFinish(ISuite suite)
Implemented to satisfy the ISuiteListener interface. A no-op.

Specified by:
onFinish in interface ISuiteListener
Parameters:
suite -

onStart

public void onStart(ISuite suite)
Generates the base report for all registered ILightestReporter's .

Specified by:
onStart in interface ISuiteListener
Parameters:
suite -

onFinish

public void onFinish(ITestContext context)
Ensures the list of failed tests maintained by the TestNG TestRunner implementation underlying the ITestContext reflects the actual test result status. We do this in the listener because the list is manipulated by the TestNG Invoker, which we can't get our hands around. Yes, this is hackish - we're seriously meddling with the TestRunner internals - but we've got to do it!

Specified by:
onFinish in interface ITestListener
Overrides:
onFinish in class TestListenerAdapter
Parameters:
context -

onStart

public void onStart(ITestContext context)
Specified by:
onStart in interface ITestListener
Overrides:
onStart in class TestListenerAdapter

onTestFailure

public void onTestFailure(ITestResult result)
Specified by:
onTestFailure in interface ITestListener
Overrides:
onTestFailure in class TestListenerAdapter

onTestSkipped

public void onTestSkipped(ITestResult result)
Specified by:
onTestSkipped in interface ITestListener
Overrides:
onTestSkipped in class TestListenerAdapter

onTestStart

public void onTestStart(ITestResult result)
Specified by:
onTestStart in interface ITestListener
Overrides:
onTestStart in class TestListenerAdapter

onTestSuccess

public void onTestSuccess(ITestResult result)
Instead of simply delegating to the TestListenerAdapter, we first check if the tasks corresponding to the test method were all OK. If not, mark the result as failed, and report failure to the adapter. This logic is housed here for convenience, because we don't have many opportunities to alter the result status. Assuming this listener implementation precedes all others in the list of listeners maintained by the TestNG instance, the desired status should be propagated correctly.

Specified by:
onTestSuccess in interface ITestListener
Overrides:
onTestSuccess in class TestListenerAdapter
Parameters:
result -

onTestFinish

public void onTestFinish(ITestResult result)
Records test run information, updates testng-results.xml, and invokes the report for all registered ILightestReporter's . The XML file is guaranteed to be created before the other reporters are invoked, and exist during their invocation (unless they delete it! or the reporter is "scheduled"). Override this to add functionality that is common to test failures, successes, and skips. Make sure to invoke the superclass' method afterwards.

Specified by:
onTestFinish in interface ILightestTestListener
Parameters:
result -

resolveResult

protected void resolveResult(ITestResult result)
Resolves the result in the registry. This method should be called either before or atomically with an update to this adapter's passed, failed, or skipped test listings; otherwise the registry is more likely to be out of sync with the recorded results at time of report generation.

Parameters:
result -

onTaskComplete

public void onTaskComplete(ITaskResult taskResult,
                           ITestResult testResult)
Adds the ITaskResult to the list kept for each ITestResult. Only root- level results are added to the list; child results are linked through the root.

Specified by:
onTaskComplete in interface ILightestTestListener
Parameters:
taskResult -
testResult - the ITestResult associated with the currently executing test

generateReport

public void generateReport(List xmlSuites,
                           List suites,
                           String outputDirectory)
Invokes generateReport() on all registered IReporter reporters. The testng-results.xml and testng-failed.xml XML files are guaranteed to be generated before the other reports are generated. This method will be invoked by the TestNG engine at the end of the suite run.

Specified by:
generateReport in interface IReporter
Parameters:
xmlSuites -
suites -
outputDirectory - this is ignored; the current value of outputDir on this object is used instead

registerReporter

public void registerReporter(Object reporter)
Description copied from interface: ILightestTestListener
Registers a new reporter to be notified of reportable events. The reporter should implement at least one of org.testng.IReporter or ILightestReporter.

Specified by:
registerReporter in interface ILightestTestListener

initializeReporters

public void initializeReporters(String configText)
Description copied from interface: ILightestTestListener
Invokes generateBaseReport() on all registered reporters that are instances of ILightestReporter.

Specified by:
initializeReporters in interface ILightestTestListener
Parameters:
configText - the textual configuration that was used to configure this run, if any. May be null.

getMetaClass

public groovy.lang.MetaClass getMetaClass()
Specified by:
getMetaClass in interface groovy.lang.GroovyObject

setMetaClass

public void setMetaClass(groovy.lang.MetaClass metaClass)
Specified by:
setMetaClass in interface groovy.lang.GroovyObject

invokeMethod

public Object invokeMethod(String name,
                           Object args)
Specified by:
invokeMethod in interface groovy.lang.GroovyObject

getProperty

public Object getProperty(String name)
Specified by:
getProperty in interface groovy.lang.GroovyObject

setProperty

public void setProperty(String name,
                        Object value)
Specified by:
setProperty in interface groovy.lang.GroovyObject


Copyright © 2009. All Rights Reserved.