1 package test.dataprovider;
2 
3 import org.testng.Assert;
4 import org.testng.TestNG;
5 import org.testng.annotations.BeforeMethod;
6 import org.testng.annotations.Test;
7 
8 import test.BaseTest;
9 
10 public class FailedDataProviderTest extends BaseTest {
11   static int m_total = 0;
12 
13   @BeforeMethod
init()14   public void init() {
15     m_total = 0;
16   }
17 
18   /**
19    * Make sure that if a test method fails in the middle of a data provider, the rest
20    * of the data set is still run.
21    */
22   @Test
allMethodsShouldBeInvoked()23   public void allMethodsShouldBeInvoked() {
24     TestNG tng = new TestNG();
25     tng.setTestClasses(new Class[] { FailedDataProviderSample.class });
26     tng.setVerbose(0);
27     tng.run();
28 
29     Assert.assertEquals(m_total, 6);
30   }
31 
32   @Test
failedDataProviderShouldCauseSkip()33   public void failedDataProviderShouldCauseSkip() {
34     addClass("test.dataprovider.DependentSampleTest");
35 
36     run();
37     String[] passed = {
38       "method1"
39     };
40     String[] failed = {
41       "method1"
42     };
43     String[] skipped = {
44       "method2"
45     };
46     verifyTests("Failed", failed, getFailedTests());
47     verifyTests("Passed", passed, getPassedTests());
48     verifyTests("Skipped", skipped, getSkippedTests());
49   }
50 }
51 
52