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;
017:
018: import org.testng.annotations.*;
019: import static org.unitils.TracingTestListener.*;
020: import org.unitils.core.TestListener;
021: import org.unitils.core.Unitils;
022:
023: /**
024: * TestNG test class containing 2 active and 1 ignored test method. This test test-class is used
025: * in the {@link UnitilsInvocationTest} and {@link UnitilsInvocationExceptionTest} tests.
026: *
027: * @author Tim Ducheyne
028: */
029: public class UnitilsTestNGTest_TestClass1 extends UnitilsTestNG {
030:
031: /* Test listener that will record all invocations */
032: private static TracingTestListener tracingTestListener;
033:
034: /**
035: * Sets the tracing test listener that will record all invocations.
036: *
037: * @param testListener the listener
038: */
039: public static void setTracingTestListener(
040: TracingTestListener testListener) {
041: tracingTestListener = testListener;
042: }
043:
044: @BeforeClass
045: public void beforeClass() {
046: addTestInvocation(TEST_BEFORE_CLASS, null);
047: }
048:
049: @AfterClass
050: public void afterClass() {
051: addTestInvocation(TEST_AFTER_CLASS, null);
052: }
053:
054: @BeforeMethod
055: public void setUp() {
056: addTestInvocation(TEST_SET_UP, null);
057: }
058:
059: @AfterMethod
060: public void tearDown() {
061: addTestInvocation(TEST_TEAR_DOWN, null);
062: }
063:
064: @Test
065: public void test1() {
066: addTestInvocation(TEST_METHOD, "test1");
067: }
068:
069: @Test
070: public void test2() {
071: addTestInvocation(TEST_METHOD, "test2");
072: }
073:
074: @Test(enabled=false)
075: public void test3() {
076: addTestInvocation(TEST_METHOD, "test3");
077: }
078:
079: /**
080: * Records an invocation.
081: *
082: * @param invocation the invocation type, not null
083: * @param testMethodName the actual test name, null if not applicable
084: */
085: private void addTestInvocation(String invocation,
086: String testMethodName) {
087: if (tracingTestListener != null) {
088: tracingTestListener.addTestInvocation(invocation, this ,
089: testMethodName);
090: }
091: }
092:
093: /**
094: * Overridden to install the tracing test listener.
095: *
096: * @return the unitils instance, not null
097: */
098: @Override
099: protected Unitils getUnitils() {
100: if (tracingTestListener != null) {
101: return new Unitils() {
102:
103: @Override
104: public TestListener createTestListener() {
105: return tracingTestListener;
106: }
107: };
108: }
109: return super.getUnitils();
110: }
111:
112: }
|