1 package test.invokedmethodlistener; 2 3 import org.testng.IInvokedMethod; 4 import org.testng.IInvokedMethodListener; 5 import org.testng.ITestResult; 6 import org.testng.annotations.Test; 7 8 public class Sample2 { 9 10 @Test(expectedExceptions = IllegalArgumentException.class) t1()11 public void t1() { 12 throw new IllegalArgumentException("Throw this exception on purpose in test"); 13 } 14 15 public class Sample2InvokedMethodListener implements IInvokedMethodListener 16 { 17 18 boolean isSuccess = false; 19 20 /** 21 * {@inheritDoc} 22 */ 23 @Override afterInvocation(IInvokedMethod m, ITestResult tr)24 public void afterInvocation(IInvokedMethod m, ITestResult tr) 25 { 26 isSuccess = tr.isSuccess(); 27 } 28 29 /** 30 * {@inheritDoc} 31 */ 32 @Override beforeInvocation(IInvokedMethod arg0, ITestResult arg1)33 public void beforeInvocation(IInvokedMethod arg0, ITestResult arg1) 34 { 35 // no need to implement this right now 36 } 37 isSuccess()38 public boolean isSuccess() { 39 return isSuccess; 40 } 41 } 42 } 43