01: package test.tmp;
02:
03: import java.io.File;
04: import java.io.FileInputStream;
05: import java.io.FileNotFoundException;
06: import java.io.IOException;
07: import java.util.ArrayList;
08: import java.util.Enumeration;
09: import java.util.List;
10: import java.util.Properties;
11:
12: import org.testng.Assert;
13: import org.testng.annotations.DataProvider;
14: import org.testng.annotations.Test;
15:
16: public class DataDrivenTest {
17:
18: @DataProvider(name="provider")
19: public Object[][] createData() throws FileNotFoundException,
20: IOException {
21: Properties p = new Properties();
22: List<Object> vResult = new ArrayList<Object>();
23: p.load(new FileInputStream(new File("c:/t/data.properties")));
24: for (Enumeration e = p.keys(); e.hasMoreElements();) {
25: vResult.add(e.nextElement());
26: }
27:
28: Object[][] result = new Object[vResult.size()][1];
29: for (int i = 0; i < result.length; i++) {
30: result[i] = new Object[] { vResult.get(i) };
31: }
32:
33: return result;
34: }
35:
36: @Test(dataProvider="provider")
37: public void foo(int n) {
38: Assert.assertTrue(n > 0);
39: }
40:
41: }
|