本系列汇总,请查看这里:https://www.cnblogs.com/uncleyong/p/15867903.html
添加pom依赖
操作excel的依赖
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.2</version>
</dependency>
测试数据文件放caseData目录
caseData.xlsx
修改testng.xml
指定参数:数据文件路径、用例sheet名、常用变量sheet名
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="apiAutoTest" verbose="1">
<parameter name="variableSheetName" value="variables"/>
<test name="register-login-add-findByName" enabled="true"> <!--test必须有name属性-->
<parameter name="excelPath" value="caseData/caseData.xlsx"/>
<parameter name="dataSheetName" value="case"/>
<classes>
<class name="com.qzcsbj.autotest.testcase.BaseCase"/>
</classes>
</test>
</suite>
创建实体类
用例
package com.qzcsbj.autotest.entity;
/**
* @博客 : www.cnblogs.com/uncleyong
* @微信 : ren168632201
* @描述 : <case类>
*/
public class CaseData {
private String caseId;
private String apiName;
private String describe;
private String url;
private String requestType;
private String headers;
private String cookies;
private String parameters;
private String uploadFile;
private String initSql;
private String globalVariables;
private String assertFields;
public String getCaseId() {
return caseId;
}
public void setCaseId(String caseId) {
this.caseId = caseId;
}
public String getApiName() {
return apiName;
}
public void setApiName(String apiName) {
this.apiName = apiName;
}
publi