01: package test.groupinvocation;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: import org.testng.Assert;
07: import org.testng.annotations.AfterClass;
08: import org.testng.annotations.AfterGroups;
09: import org.testng.annotations.BeforeGroups;
10: import org.testng.annotations.Test;
11:
12: /**
13: * This class/interface
14: */
15: public class DummyTest {
16: private static Map<String, Integer> s_externalClassGroups = new HashMap<String, Integer>();
17:
18: @Test(groups={"a"})
19: public void testA() {
20: }
21:
22: @Test(groups={"b"})
23: public void testB() {
24: }
25:
26: @Test(groups={"a","b"})
27: public void testAB() {
28: }
29:
30: @AfterClass(alwaysRun=true)
31: public void checkInvocations() {
32: Integer hashCode1 = s_externalClassGroups.get("beforeGroups");
33: Assert.assertNotNull(hashCode1,
34: "External @BeforeGroups not invoked");
35: Integer hashCode2 = s_externalClassGroups.get("afterGroups");
36: Assert.assertNotNull(hashCode2,
37: "External @AfterGroups not invoked");
38: Assert.assertEquals(hashCode1, hashCode2,
39: "External @BeforeGroups and @AfterGroups were not invoked on the"
40: + " same class instance");
41: }
42:
43: /**
44: * @param string
45: * @param i
46: */
47: public static void recordInvocation(String string, int i) {
48: s_externalClassGroups.put(string, i);
49: }
50: }
|