Home | History | Annotate | Download | only in test
      1 package test;
      2 
      3 import org.testng.annotations.AfterTest;
      4 import org.testng.annotations.Test;
      5 
      6 /**
      7  * this test verifys that the test class is instantiated exactly once
      8  * regardless of how many test methods we have, showing that TestNG
      9  * semantics is quite different from JUnit
     10  */
     11 public class CtorCalledOnce {
     12   public static int instantiated = 0;
     13   public CtorCalledOnce() {
     14     instantiated++;
     15   }
     16 
     17   @Test
     18   public void testMethod1(){
     19     assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
     20   }
     21 
     22   @Test
     23   public void testMethod2(){
     24     assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
     25   }
     26 
     27   @Test
     28   public void testMethod3(){
     29     assert instantiated == 1 : "Expected 1, was invoked " + instantiated + " times";
     30   }
     31 
     32   @AfterTest
     33   public void afterTest() {
     34     instantiated = 0;
     35   }
     36 
     37 }