其他分享
首页 > 其他分享> > DataProvider学习笔记

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>

标签:httpEntity,String,Object,笔记,学习,MyHttpEntity,import,lombok,DataProvider
来源: https://blog.51cto.com/357712148/2368274