001: /*
002: * Copyright 2006-2007, Unitils.org
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.unitils.core;
017:
018: import java.lang.reflect.Method;
019:
020: /**
021: * Listener for test events. The events must follow following ordering:
022: * <ul>
023: * <li>[Unitils] beforeAll</li>
024: * <li>[Unitils] beforeTestClass - TestClass1</li>
025: * <li>[Test] testBeforeClass - TestClass1 (not for JUnit3)</li>
026: * <li>[Unitils] beforeTestSetUp - TestClass1</li>
027: * <li>[Test] testSetUp - TestClass1</li>
028: * <li>[Unitils] beforeTestMethod - TestClass1 - test1</li>
029: * <li>[Test] testMethod - TestClass1 - test1</li>
030: * <li>[Unitils] afterTestMethod - TestClass1 - test1</li>
031: * <li>[Test] testTearDown - TestClass1</li>
032: * <li>[Unitils] afterTestTearDown - TestClass1</li>
033: * <li>[Unitils] beforeTestSetUp - TestClass1</li>
034: * <li>[Test] testSetUp - TestClass1</li>
035: * <li>[Unitils] beforeTestMethod - TestClass1 - test2</li>
036: * <li>[Test] testMethod - TestClass1 - test2</li>
037: * <li>[Unitils] afterTestMethod - TestClass1 - test2</li>
038: * <li>[Test] testTearDown - TestClass1</li>
039: * <li>[Unitils] afterTestTearDown - TestClass1</li>
040: * <li>[Test] testAfterClass - TestClass1 (not for JUnit3)</li>
041: * <li>[Unitils] afterTestClass - TestClass1</li>
042: * <li>[Unitils] afterAll</li>
043: * </ul>
044: * <p/>
045: * The after methods will always when the before counterpart has run (or begun). For example if an exception occurs during
046: * the beforeTestClass method, the afterTestClass will still be called.
047: *
048: * @author Tim Ducheyne
049: * @author Filip Neven
050: */
051: public abstract class TestListener {
052:
053: /**
054: * Invoked before any of the tests are run.
055: * This can be overriden to for example add general initialisation.
056: */
057: public void beforeAll() {
058: // empty
059: }
060:
061: /**
062: * Invoked before any of the test in a test class are run.
063: * This can be overriden to for example add test-class initialisation.
064: *
065: * @param testClass The test class, not null
066: */
067: public void beforeTestClass(Class<?> testClass) {
068: // empty
069: }
070:
071: /**
072: * Invoked before the test setup (eg @Before) is run.
073: * This can be overriden to for example initialize the test-fixture.
074: *
075: * @param testObject The test instance, not null
076: */
077: public void beforeTestSetUp(Object testObject) {
078: // empty
079: }
080:
081: /**
082: * Invoked before the test but after the test setup (eg @Before) is run.
083: * This can be overriden to for example further initialize the test-fixture using values that were set during
084: * the test setup.
085: *
086: * @param testObject The test instance, not null
087: * @param testMethod The test method, not null
088: */
089: public void beforeTestMethod(Object testObject, Method testMethod) {
090: // empty
091: }
092:
093: /**
094: * Invoked after the test run but before the test tear down (eg @After).
095: * This can be overriden to for example add assertions for testing the result of the test.
096: * It the before method or the test raised an exception, this exception will be passed to the method.
097: *
098: * @param testObject The test instance, not null
099: * @param testMethod The test method, not null
100: * @param testThrowable The throwable thrown during the test or beforeTestMethod, null if none was thrown
101: */
102: public void afterTestMethod(Object testObject, Method testMethod,
103: Throwable testThrowable) {
104: // empty
105: }
106:
107: /**
108: * Invoked after the test tear down (eg @After).
109: * This can be overriden to for example peform extra cleanup after the test.
110: *
111: * @param testObject The test instance, not null
112: */
113: public void afterTestTearDown(Object testObject) {
114: // empty
115: }
116:
117: /**
118: * Invoked after all tests of a test class have run.
119: * This can be overriden to for example peform extra cleanup after the test.
120: *
121: * @param testClass The test class, not null
122: */
123: public void afterTestClass(Class<?> testClass) {
124: // empty
125: }
126:
127: /**
128: * Invoked after all of the tests have run.
129: * This can be overriden to for example add general finalisation.
130: */
131: public void afterAll() {
132: // empty
133: }
134:
135: }
|