01: package test.configuration;
02:
03: import org.testng.Assert;
04: import org.testng.annotations.AfterGroups;
05: import org.testng.annotations.Test;
06:
07: /**
08: * afterGroups test with more than one group
09: *
10: * @author cbeust
11: * @date Mar 7, 2006
12: */
13: public class ConfigurationGroups5SampleTest {
14:
15: private boolean m_after = false;
16: private boolean m_run1 = false;
17: private boolean m_run2 = false;
18: private int m_afterCount = 0;
19:
20: @Test
21: public void f() {
22: log("f");
23: }
24:
25: @Test(groups="cg5-1")
26: public void run1() {
27: log("run1");
28: if (m_afterCount == 0)
29: Assert.assertFalse(m_after);
30: m_run1 = true;
31: }
32:
33: @Test(groups="cg5-2")
34: public void run2() {
35: log("run2");
36: if (m_afterCount == 0)
37: Assert.assertFalse(m_after);
38: m_run2 = true;
39: }
40:
41: @AfterGroups({"cg5-1","cg5-2"})
42: public void after() {
43: log("after");
44: m_afterCount++;
45: Assert.assertTrue(m_run1 || m_run2);
46: if (m_afterCount == 0)
47: Assert.assertFalse(m_after);
48: m_after = true;
49: }
50:
51: @Test(dependsOnGroups={"cg5-1","cg5-2"})
52: public void verify() {
53: log("verify");
54: Assert.assertTrue(m_run1, "run1() wasn't run");
55: Assert.assertTrue(m_run2, "run2() wasn't run");
56: Assert.assertTrue(m_after, "after1() wasn't run");
57: Assert.assertEquals(2, m_afterCount);
58: }
59:
60: private void log(String string) {
61: ppp(string);
62: }
63:
64: private void ppp(String s) {
65: if (false) {
66: System.out.println("[ConfigurationGroups5SampleTest] " + s);
67: }
68: }
69:
70: }
|