Home | History | Annotate | Download | only in sample
      1 package test.sample;
      2 
      3 import org.testng.annotations.AfterClass;
      4 import org.testng.annotations.BeforeClass;
      5 import org.testng.annotations.Test;
      6 
      7 /**
      8  * Check to see that AfterClass is called only at the end and that after methods
      9  * are called in reverse order of the before methods.
     10  */
     11 public class AfterClassCalledAtEnd extends BaseAfterClassCalledAtEnd {
     12   boolean m_before1Class = false;
     13   boolean m_test1 = false;
     14   boolean m_test2 = false;
     15   boolean m_test3 = false;
     16 
     17   @BeforeClass(groups = { "before1Class" } )
     18   public void before1Class() {
     19     m_before1Class = true;
     20   }
     21 
     22   @AfterClass(groups = { "someGroup" })
     23   public void afterClass() {
     24     m_afterClass = true;
     25     assert m_test1 && m_test2 && m_test3 :
     26       "One of the test methods was not invoked: " + m_test1 + " " + m_test2 + " " + m_test3;
     27   }
     28 
     29   @Test(description = "Verify that beforeClass and afterClass are called correctly")
     30   public void test1() {
     31     m_test1 = true;
     32     assert m_before1Class : "beforeClass configuration must be called before method";
     33     assert ! m_afterClass : "afterClass configuration must not be called before test method";
     34   }
     35 
     36   @Test
     37   public void test2() {
     38     m_test2 = true;
     39     assert m_before1Class : "beforeClass configuration must be called before method";
     40     assert ! m_afterClass : "afterClass configuration must not be called before test method";
     41   }
     42 
     43   @Test
     44   public void test3() {
     45     m_test3 = true;
     46     assert m_before1Class : "beforeClass configuration must be called before method";
     47     assert ! m_afterClass : "afterClass configuration must not be called before test method";
     48   }
     49 
     50 }