1package test.configuration; 2 3import org.testng.Assert; 4import org.testng.annotations.BeforeGroups; 5import org.testng.annotations.Test; 6 7import java.util.ArrayList; 8import java.util.List; 9 10/** 11 * beforeGroups test: make sure that the beforeGroups method is invoked 12 * only once even if two test methods belong to the group 13 * 14 * @author cbeust 15 * @date Mar 3, 2006 16 */ 17public class ConfigurationGroups2SampleTest { 18 private boolean m_before = false; 19 private boolean m_f1 = false; 20 private boolean m_g1 = false; 21 22 @BeforeGroups("cg2-1") 23 public void before1() { 24 Assert.assertFalse(m_before); 25 Assert.assertFalse(m_f1); 26 Assert.assertFalse(m_g1); 27 m_before = true; 28 log("before1"); 29 } 30 31 @Test(groups = "cg2-a") 32 public void fa() { 33 log("fa"); 34 } 35 36 @Test(groups = "cg2-1") 37 public void f1() { 38 Assert.assertTrue(m_before); 39 m_f1 = true; 40 log("f1"); 41 } 42 43 @Test(groups = "cg2-1") 44 public void g1() { 45 Assert.assertTrue(m_before); 46 m_g1 = true; 47 log("g1"); 48 } 49 50 private List<String> m_list = new ArrayList<>(); 51 52 @Test(dependsOnGroups = {"cg2-a", "cg2-1"}) 53 public void verify() { 54 Assert.assertTrue(m_before); 55 Assert.assertTrue(m_f1); 56 Assert.assertTrue(m_g1); 57 } 58 59 private void log(String s) { 60 m_list.add(s); 61 ppp(s); 62 } 63 64 private void ppp(String s) { 65 if (false) { 66 System.out.println("[ConfigurationGroups2SampleTest] " + s); 67 } 68 } 69 70} 71