01: package test.dataprovider;
02:
03: import org.testng.Assert;
04: import org.testng.ITestContext;
05: import org.testng.annotations.DataProvider;
06: import org.testng.annotations.Test;
07:
08: /**
09: * Tests that when a DataProvider is declared with an ITestContext,
10: * this parameter is correctly passed.
11: *
12: * Created on Dec 28, 2006
13: * @author <a href="mailto:cedric@beust.com">Cedric Beust</a>
14: */
15: public class TestContextSampleTest {
16:
17: /**
18: * @return As many parameters as the name of the included group
19: */
20: @DataProvider(name="testContext")
21: public Object[][] createContext(ITestContext ctx) {
22: // ppp("CONTEXT:" + ctx);
23: String[] groups = ctx.getIncludedGroups();
24:
25: int n = groups.length > 0 ? new Integer(groups[0]) : 0;
26: Object[] result = new Object[n];
27: for (int i = 0; i < n; i++) {
28: result[i] = "foo";
29: }
30:
31: return new Object[][] { new Object[] { result }, };
32: }
33:
34: private static void ppp(String s) {
35: System.out.println("[TestContextSampleTest] " + s);
36: }
37:
38: @Test(dataProvider="testContext",groups="10")
39: public void verifyTen(Object[] objects) {
40: Assert.assertEquals(objects.length, 10);
41: }
42:
43: @Test(dataProvider="testContext",groups="5")
44: public void verifyFive(Object[] objects) {
45: Assert.assertEquals(objects.length, 5);
46: }
47:
48: }
|