1 package test.dataprovider; 2 3 import org.testng.Assert; 4 import org.testng.annotations.DataProvider; 5 import org.testng.annotations.Test; 6 import org.testng.annotations.TestInstance; 7 8 import java.lang.reflect.Method; 9 10 public class TestInstanceTest { 11 12 private int m_n; 13 private static int m_instanceCount = 0; 14 TestInstanceTest()15 public TestInstanceTest() {} 16 TestInstanceTest(int n)17 public TestInstanceTest(int n) { 18 this.m_n = n; 19 } 20 21 @DataProvider dp(Method m, @TestInstance Object instance)22 public Object[][] dp(Method m, @TestInstance Object instance) { 23 TestInstanceTest o0 = (TestInstanceTest) instance; 24 Assert.assertTrue(o0.m_n == 1 || o0.m_n == 2); 25 m_instanceCount++; 26 return new Object[][] { 27 new Object[] {42}, 28 new Object[] {43}, 29 }; 30 } 31 32 @Test(dataProvider = "dp") f(int o)33 public void f(int o) { 34 } 35 36 @Override toString()37 public String toString() { 38 return "[A n:" + m_n + "]"; 39 } 40 ppp(String s)41 private static void ppp(String s) { 42 System.out.println("[A] " + s); 43 } 44 }