1 package test.dataprovider; 2 3 import org.testng.Assert; 4 import org.testng.TestListenerAdapter; 5 import org.testng.TestNG; 6 import org.testng.annotations.Test; 7 8 9 /** 10 * TESTNG-291: 11 * Exceptions thrown by Iterable DataProviders are not caught, no failed test reported 12 */ 13 public class FailingIterableDataProviderTest { 14 @Test 15 public void failingDataProvider() { 16 TestNG testng= new TestNG(false); 17 testng.setTestClasses(new Class[] {FailingIterableDataProvider.class}); 18 TestListenerAdapter tla = new TestListenerAdapter(); 19 testng.addListener(tla); 20 testng.setVerbose(0); 21 try { 22 testng.run(); 23 } catch (RuntimeException e) { 24 Assert.fail("Exceptions thrown during tests should always be caught!", e); 25 } 26 Assert.assertEquals(tla.getFailedTests().size(), 1, 27 "Should have 1 failure from a bad data-provider iteration"); 28 Assert.assertEquals(tla.getPassedTests().size(), 5, 29 "Should have 5 passed test from before the bad data-provider iteration"); 30 } 31 }