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