Java读取Excel测试用例
时间: 2023-10-25 20:59:22 浏览: 128
Java可以使用Apache POI库来读取Excel测试用例。你可以使用以下代码来读取Excel文件:
```java
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.IOException;
public class ReadExcel {
public static void main(String\[\] args) {
String filePath = "path/to/your/excel/file.xlsx";
try {
FileInputStream fis = new FileInputStream(filePath);
Workbook workbook = new XSSFWorkbook(fis);
Sheet sheet = workbook.getSheet("Sheet1"); // 根据实际的Sheet名称进行修改
for (Row row : sheet) {
for (Cell cell : row) {
String cellValue = "";
if (cell.getCellType() == CellType.STRING) {
cellValue = cell.getStringCellValue();
} else if (cell.getCellType() == CellType.NUMERIC) {
cellValue = String.valueOf(cell.getNumericCellValue());
}
System.out.print(cellValue + "\t");
}
System.out.println();
}
workbook.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
上述代码使用了Apache POI库来读取Excel文件。你需要将`filePath`变量修改为你实际的Excel文件路径,并根据实际的Sheet名称进行修改。代码会逐行读取Excel文件中的数据,并打印输出。
引用\[1\]中的代码是一个测试数据提供者的示例,它使用了`Files.readExcel`方法来读取Excel文件中的测试数据。这段代码与Java读取Excel测试用例的代码没有直接的关联。
#### 引用[.reference_title]
- *1* [Java 实现Excel文件读取](https://blog.csdn.net/xiaohii/article/details/115029894)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [python+unittest+requests+HTMLTestRunner 框架通过读取excel测试用例实现接口自动化测试](https://blog.csdn.net/qq_44895342/article/details/127313175)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)