这篇文章给大家介绍如何解析DataProvider,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
实体
import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import lombok.extern.log4j.Log4j; import java.util.Map; /** * @author liwen406 * @Title: MyHttpEntity * @Description: 请求实体类 * @date 2019/3/24 / 17:54 */ @Log4j @Data @NoArgsConstructor @AllArgsConstructor @Accessors(chain = true) public class MyHttpEntity { String url; String ip; String body; String info; Map<String, ?> parameter; Map<String, String> header; }
数据读取
@Data @Log4j public class Dataprovidert { @DataProvider public Object[][] getparam() { int k = 0; String[] param = {"2367952", "2367141", "2366552", "2364334"}; Object[][] result = new Object[param.length][]; for (int i = 0; i < param.length; i++) { MyHttpEntity httpEntity = new MyHttpEntity(); httpEntity.setUrl("https://blog.51cto.com/357712148/" + param[i]); result[k++] = new Object[]{httpEntity}; } return result; } }
运行测试类
@Test(dataProvider = "getparam", dataProviderClass = Dataprovidert.class) public void mydatep(MyHttpEntity httpEntity) { HttpResponse response = HttpRequest.get(httpEntity.url).execute(); log.info("response" + response.body()); }
pom.xml
<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.4.0</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.4</version> <scope>provided</scope> </dependency>
关于如何解析DataProvider就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/204607.html