01: package test.dataprovider;
02:
03: import org.testng.Assert;
04:
05: public class MultipleDataProviderTest {
06: private int m_countTest1;
07: private boolean m_okeTest1;
08: private int m_countTest2;
09: private boolean m_okeTest2;
10:
11: /**
12: * This method will provide data to any test method that declares that
13: * its Data Provider is named "test1"
14: *
15: * @testng.data-provider name="test1"
16: */
17: public Object[][] createData1() {
18: Object[][] inputs = new Object[][] {
19: new Object[] { "Name1", new Integer(46), new Integer(1) },
20: new Object[] { "Name2", new Integer(47), new Integer(2) },
21: new Object[] { "Name3", new Integer(43), new Integer(3) } };
22:
23: return inputs;
24: }
25:
26: /**
27: * This test method declares that its data should be supplied by the
28: * Data Provider named "test1"
29: *
30: * @testng.test groups="mytest1" dataProvider="test1"
31: */
32: public void verifyData1(String n1, Integer n2, Integer n3) {
33: m_countTest1++;
34: if (n3.equals(new Integer(1)) || n3.equals(new Integer(2))
35: || n3.equals(new Integer(3))) {
36: m_okeTest1 = true;
37: } else {
38: m_okeTest1 = false;
39: }
40: }
41:
42: /**
43: * @testng.test dependsOnMethods="verifyData1"
44: */
45: public void verifyTest1DataProvider() {
46: Assert.assertEquals(m_countTest1, 3,
47: "verifyData1 should have been invoked 3 times,"
48: + "as per its @DataProvider");
49: Assert.assertTrue(m_okeTest1,
50: "looks like another @DataProvider has been used");
51: }
52:
53: /**
54: * This method will provide data to any test method that declares that
55: * its Data Provider is named "test2"
56: *
57: * @testng.data-provider name="test2"
58: */
59: public Object[][] createData2() {
60: Object[][] inputs = new Object[][] {
61: new Object[] { "Cedric", new Integer(36),
62: new Integer(1) },
63: new Object[] { "Anne", new Integer(37), new Integer(2) },
64: new Object[] { "John", new Integer(23), new Integer(3) },
65: new Object[] { "Mary", new Integer(13), new Integer(4) } };
66:
67: return inputs;
68: }
69:
70: /**
71: * This test method declares that its data should be supplied by the
72: * Data Provider named "test2"
73: *
74: * @testng.test groups="mytest2" dataProvider="test2"
75: */
76: public void verifyData2(String n1, Integer n2, Integer n3) {
77: m_countTest2++;
78: if ("Cedric".equals(n1) || "Anne".equals(n1)
79: || "John".equals(n1) || "Mary".equals(n1)) {
80: m_okeTest2 = true;
81: } else {
82: m_okeTest2 = false;
83: }
84: }
85:
86: /**
87: * @testng.test dependsOnMethods="verifyData2"
88: */
89: public void verifyTest2DataProvider() {
90: Assert.assertEquals(m_countTest2, 4,
91: "verifyData2 should have been invoked 4 times,"
92: + "as per its @DataProvider");
93: Assert.assertTrue(m_okeTest2,
94: "looks like another @DataProvider has been used");
95: }
96: }
|