• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test.configuration;
2 
3 import org.testng.Assert;
4 import org.testng.annotations.AfterGroups;
5 import org.testng.annotations.Test;
6 
7 /**
8  * afterGroups test with more than one group
9  *
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
f()21   public void f() {
22     log("f");
23   }
24 
25   @Test(groups = "cg5-1")
run1()26   public void run1() {
27     log("run1");
28     if (m_afterCount == 0) {
29       Assert.assertFalse(m_after);
30     }
31     m_run1 = true;
32   }
33 
34   @Test(groups = "cg5-2")
run2()35   public void run2() {
36     log("run2");
37     if (m_afterCount == 0) {
38       Assert.assertFalse(m_after);
39     }
40     m_run2 = true;
41   }
42 
43   @AfterGroups({ "cg5-1", "cg5-2"})
after()44   public void after() {
45     log("after");
46     m_afterCount++;
47     Assert.assertTrue(m_run1 || m_run2);
48     if (m_afterCount == 0) {
49       Assert.assertFalse(m_after);
50     }
51     m_after = true;
52   }
53 
54   @Test(dependsOnGroups = { "cg5-1", "cg5-2" })
verify()55   public void verify() {
56     log("verify");
57     Assert.assertTrue(m_run1, "run1() wasn't run");
58     Assert.assertTrue(m_run2, "run2() wasn't run");
59     Assert.assertTrue(m_after, "after1() wasn't run");
60     Assert.assertEquals(2, m_afterCount);
61   }
62 
log(String string)63   private void log(String string) {
64     ppp(string);
65   }
66 
ppp(String s)67   private void ppp(String s) {
68     if (false) {
69       System.out.println("[ConfigurationGroups5SampleTest] " + s);
70     }
71   }
72 
73 }
74