1 package test.configuration; 2 3 import org.testng.Assert; 4 import org.testng.annotations.BeforeGroups; 5 import org.testng.annotations.Test; 6 7 import java.util.ArrayList; 8 import java.util.List; 9 10 /** 11 * beforeGroups test: make sure that if before methods are scattered on 12 * more than one class, they are still taken into account 13 * 14 * @author cbeust 15 * @date Mar 3, 2006 16 */ 17 public class ConfigurationGroups3SampleTest extends Base3 { 18 private boolean m_before = false; 19 static private boolean m_f1 = false; 20 21 @BeforeGroups("cg34-1") before1()22 public void before1() { 23 Assert.assertFalse(m_before); 24 Assert.assertFalse(m_f1); 25 m_before = true; 26 log("before1"); 27 } 28 29 @Test(groups = "cg34-a") fa()30 public void fa() { 31 log("fa"); 32 } 33 34 @Test(groups = "cg34-1") f1()35 public void f1() { 36 Assert.assertTrue(m_before); 37 Assert.assertTrue(Base3.getBefore()); 38 m_f1 = true; 39 log("f1"); 40 } 41 42 private List<String> m_list = new ArrayList<>(); 43 44 @Test(dependsOnGroups = {"cg34-a", "cg34-1"}) verify()45 public void verify() { 46 Assert.assertTrue(m_before); 47 Assert.assertTrue(Base3.getBefore()); 48 Assert.assertTrue(m_f1); 49 } 50 log(String s)51 private void log(String s) { 52 m_list.add(s); 53 ppp(s); 54 } 55 ppp(String s)56 private void ppp(String s) { 57 if (false) { 58 System.out.println("[ConfigurationGroups3SampleTest] " + s); 59 } 60 } 61 getF1()62 public static boolean getF1() { 63 return m_f1; 64 } 65 66 } 67