我的所有请求都失败了,似乎我无法将数据从dataprovider传递到json字段。有什么想法和想法吗?
我正在使用@dataprovider为我的性能测试传递多个值。我为dataprovider中的每个值获取状态代码200,但无法将dataprovider值传递给Json字段“values”。值字段获取每个数据提供者值并请求api获取信息。
package com.company.testing;
import static io.restassured.RestAssured.given;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import io.restassured.response.Response;
public class test1 {
Response myResponse;
String baseURL = "http://test.com/1.0/api";
@DataProvider(name = "data")
public Object[][] createTestData() {
return new Object[][]{
{"some1.com"},
{"some2.net"},
{"some3.com"},
{"some4.com"}};
}
@Test(dataProvider = "data")
public void potTest(String values){
Response myResponse;
String baseURL = "http://test.com/1.0/api";
System.out.println(values);
String Json = buildJson(values);
myResponse = given().contentType("application/json").body(Json).when().post(baseURL);
//Print Response
//System.out.println("Request :" + Json);
System.out.println("Response Body : "+myResponse.getBody().asString());
System.out.println("Response Code : "+myResponse.getStatusCode());
System.out.println("Response Time : "+myResponse.getTime());
}
String buildJson(String values){
return "{\n" +
" \"oemid\":\"company1\",\n" +
" \"deviceid\":\"DeviceId\",\n" +
" \"uid\":\"system1\", \n" +
" \"values\":\n" +
" [\"values\"], \n" +
" \"queries\":\n" +
" [\"gethistory\"], \n" +
" \"starttime\" : \"2017-06-10T00:00:00\", \n" +
" \"endtime\" : \"2017-08-25T00:00:00\", \n" +
" \"xml\":0, \n" +
" \"nocache\":1 \n" +
" }\n";
}
}
答案 0 :(得分:4)
您的buildJson方法根本没有使用该参数。用
替换值部分 " \"values\":[" + values + "\"]" +