这是我的代码。我从两个 CSV 文件(一个用于用户,一个用于餐厅)中读取数据,并且我在 Selenium Webdriver 中提供了两个不同的测试类和两个不同的数组,以便对测试进行参数化。
有什么办法我不在这里重复这么多代码吗?
final String FILE_PATH = "src/test/resources/250.csv";
final String FILE_PATH2 = "src/test/resources/places.csv";
//read CSV file and supply data for test purposes
CSVReader reader = new CSVReader(new FileReader(FILE_PATH));
ArrayList<ArrayList<String>> array = new ArrayList<ArrayList<String>>();
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < 5; i++) { // 5 is the number of columns
list.add(nextLine[i]);
}
array.add(list);
}
reader.close();
CSVReader reader2 = new CSVReader(new FileReader(FILE_PATH2));
ArrayList<ArrayList<String>> array2 = new ArrayList<ArrayList<String>>();
String[] nextLine2;
while ((nextLine2 = reader2.readNext()) != null) {
ArrayList<String> list2 = new ArrayList<String>();
for (int i = 0; i < 5; i++) { // 5 is the number of columns
list2.add(nextLine2[i]);
}
array2.add(list2);
}
reader2.close();