自定义数据驱动器内容20210912
1. 自定义数据驱动内容:
import java.io.IOException;
import java.util.List;
public class DefineDataProviderMethod {
public static String excelFileName = "D:\\Code\\testfile.xlsx";
public static String sheetName = "";
public static List<CaseInfo> getDataProvider(String type) throws IOException {
if(type.equals("api可用性")){
sheetName = "SAM_APIFun";
}else if(type.equals("api比较")){
sheetName = "ECM_APITest";
}
return CaseInfoFilter.generateCaseObjectList(excelFileName, sheetName);
}
}
2. 测试用例逻辑:
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
public class AppTest
{
static Boolean status = Boolean.TRUE;
static List<CaseInfo> datainfo = null;
@BeforeTest
public void beforeTest() throws IOException {
datainfo = DefineDataProviderMethod.getDataProvider("api比较");
}
/*
自定义数据驱动方法
*/
@Test
public void runTest(){
HashMap<String,String> result = new HashMap<>();
for (CaseInfo info : datainfo) {
System.out.println(info.getCaseName());
if(!info.getApiParam().equals("myparam")){
status = Boolean.FALSE;
System.out.println("=============参数不等=========");
result.put(info.getCaseName(),info.getApiParam());
}
}
if(result.isEmpty()){
Assert.assertTrue(Boolean.TRUE);
System.out.println("==用例成功====");
}else {
Assert.assertEquals(Boolean.TRUE,status,result.toString());
}
}
}
import java.io.IOException;
import java.util.List;
public class DefineDataProviderMethod {
public static String excelFileName = "D:\\Code\\testfile.xlsx";
public static String sheetName = "";
public static List<CaseInfo> getDataProvider(String type) throws IOException {
if(type.equals("api可用性")){
sheetName = "SAM_APIFun";
}else if(type.equals("api比较")){
sheetName = "ECM_APITest";
}
return CaseInfoFilter.generateCaseObjectList(excelFileName, sheetName);
}
}

浙公网安备 33010602011771号