1 package test.skipex;
2 
3 import org.testng.Assert;
4 import org.testng.ITestResult;
5 import org.testng.TestListenerAdapter;
6 import org.testng.TestNG;
7 import org.testng.annotations.Test;
8 
9 import java.util.List;
10 
11 
12 /**
13  * This class/interface
14  */
15 public class SkippedExceptionTest {
16   @Test
skippedExceptionInConfigurationMethods()17   public void skippedExceptionInConfigurationMethods() {
18     TestListenerAdapter listener= new TestListenerAdapter();
19     TestNG test= new TestNG(false);
20     test.addListener(listener);
21     test.setVerbose(0);
22     test.setTestClasses(new Class[] {ConfigurationSkippedExceptionTest.class});
23     test.run();
24     List<ITestResult> confSkips= listener.getConfigurationSkips();
25     List<ITestResult> testSkips= listener.getSkippedTests();
26     Assert.assertEquals(testSkips.size(), 1);
27     Assert.assertEquals(testSkips.get(0).getMethod().getMethodName(), "dummyTest");
28 
29     Assert.assertEquals(confSkips.size(), 1);
30     Assert.assertEquals(confSkips.get(0).getMethod().getMethodName(), "configurationLevelSkipException");
31   }
32 
33 
34   @Test
skippedExceptionInTestMethods()35   public void skippedExceptionInTestMethods() {
36     TestListenerAdapter listener= new TestListenerAdapter();
37     TestNG test= new TestNG(false);
38     test.addListener(listener);
39     test.setTestClasses(new Class[] {TestSkippedExceptionTest.class});
40     test.run();
41     List<ITestResult> skips= listener.getSkippedTests();
42     List<ITestResult> failures= listener.getFailedTests();
43     List<ITestResult> passed = listener.getPassedTests();
44     Assert.assertEquals(skips.size(), 1);
45     Assert.assertEquals(failures.size(), 1);
46     Assert.assertEquals(passed.size(), 1);
47     Assert.assertEquals(skips.get(0).getMethod().getMethodName(), "genericSkipException");
48     Assert.assertEquals(failures.get(0).getMethod().getMethodName(), "timedSkipException");
49     Assert.assertEquals(passed.get(0).getMethod().getMethodName(), "genericExpectedSkipException");
50   }
51 }
52