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