org.unitils.core
Class TestListener

java.lang.Object
  extended by org.unitils.core.TestListener
Direct Known Subclasses:
DatabaseModule.DatabaseTestListener, DbUnitModule.DbUnitListener, EasyMockModule.EasyMockTestListener, FileContentAnnotationHandler, InjectModule.InjectTestListener, IOModule.IOTestListener, MockModule.MockTestListener, OrmModule.OrmTestListener, SpringModule.SpringTestListener, TempDirAnnotationHandler, TempFileAnnotationHandler, TracingTestListener

public abstract class TestListener
extends Object

Listener for test events. The events must follow following ordering:

The after methods will always when the before counterpart has run (or begun). For example if an exception occurs during the beforeTestSetup method, the afterTestTearDown method will still be called.

Is implemented as an abstract class with empty methods instead of an interface, since most implementations only need to implement a small subset of the provided callback methods.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
TestListener()
           
 
Method Summary
 void afterCreateTestObject(Object testObject)
          Invoked before any of the test in a test class are run.
 void afterTestMethod(Object testObject, Method testMethod, Throwable testThrowable)
          Invoked after the test run but before the test tear down (e.g.
 void afterTestTearDown(Object testObject, Method testMethod)
          Invoked after the test tear down (eg @After).
 void beforeTestClass(Class<?> testClass)
          Invoked before the generic class setup (e.g.
 void beforeTestMethod(Object testObject, Method testMethod)
          Invoked before the test but after the test setup (eg @Before) is run.
 void beforeTestSetUp(Object testObject, Method testMethod)
          Invoked before the test setup (eg @Before) is run.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestListener

public TestListener()
Method Detail

beforeTestClass

public void beforeTestClass(Class<?> testClass)
Invoked before the generic class setup (e.g. @BeforeClass) is performed.

Parameters:
testClass - The class whose test methods are about to be executed, not null

afterCreateTestObject

public void afterCreateTestObject(Object testObject)
Invoked before any of the test in a test class are run. This can be overridden to for example add test-class initialization.

Parameters:
testObject - The test class, not null

beforeTestSetUp

public void beforeTestSetUp(Object testObject,
                            Method testMethod)
Invoked before the test setup (eg @Before) is run. This can be overridden to for example initialize the test-fixture.

Parameters:
testObject - The test instance, not null
testMethod - The test method, not null

beforeTestMethod

public void beforeTestMethod(Object testObject,
                             Method testMethod)
Invoked before the test but after the test setup (eg @Before) is run. This can be overridden to for example further initialize the test-fixture using values that were set during the test setup.

Parameters:
testObject - The test instance, not null
testMethod - The test method, not null

afterTestMethod

public void afterTestMethod(Object testObject,
                            Method testMethod,
                            Throwable testThrowable)
Invoked after the test run but before the test tear down (e.g. @After). This can be overridden to for example add assertions for testing the result of the test. It the before method or the test raised an exception, this exception will be passed to the method.

Parameters:
testObject - The test instance, not null
testMethod - The test method, not null
testThrowable - The throwable thrown during the test or beforeTestMethod, null if none was thrown

afterTestTearDown

public void afterTestTearDown(Object testObject,
                              Method testMethod)
Invoked after the test tear down (eg @After). This can be overridden to for example perform extra cleanup after the test.

Parameters:
testObject - The test instance, not null
testMethod - The test method, not null


Copyright © 2011. All Rights Reserved.