Home | History | Annotate | Download | only in listeners
      1 package test.listeners;
      2 
      3 import org.testng.Assert;
      4 import org.testng.IConfigurationListener2;
      5 import org.testng.ITestResult;
      6 import org.testng.TestNG;
      7 import org.testng.annotations.Test;
      8 
      9 import test.SimpleBaseTest;
     10 
     11 public class ConfigurationListenerTest extends SimpleBaseTest {
     12 
     13   static public class CL implements IConfigurationListener2 {
     14 
     15     private static int m_status = 0;
     16 
     17     @Override
     18     public void beforeConfiguration(ITestResult tr) {
     19       m_status += 1;
     20     }
     21 
     22     @Override
     23     public void onConfigurationSuccess(ITestResult itr) {
     24       m_status += 3;
     25     }
     26 
     27     @Override
     28     public void onConfigurationFailure(ITestResult itr) {
     29       m_status += 5;
     30     }
     31 
     32     @Override
     33     public void onConfigurationSkip(ITestResult itr) {
     34       m_status += 7;
     35     }
     36 
     37   }
     38 
     39   private void runTest(Class<?> cls, int expected) {
     40     TestNG tng = create(cls);
     41     CL listener = new CL();
     42     CL.m_status = 0;
     43     tng.addListener(listener);
     44     tng.run();
     45 
     46     Assert.assertEquals(CL.m_status, expected);
     47   }
     48 
     49   @Test
     50   public void shouldSucceed() {
     51     runTest(ConfigurationListenerSucceedSampleTest.class, 1 + 3);
     52   }
     53 
     54   @Test
     55   public void shouldFail() {
     56     runTest(ConfigurationListenerFailSampleTest.class, 1 + 5);
     57   }
     58 
     59   @Test
     60   public void shouldSkip() {
     61     runTest(ConfigurationListenerSkipSampleTest.class, 1 + 5 + 7); // fail + skip
     62   }
     63 }
     64