在Rest Assured Framework中,POST响应未显示创建的ID和我通过POSTMAN获得的时间。
@Test
public void newuser() {
service = new services();
// response = service.addProduct("444", "OIL","Natural Tea Tree", "210.0");
response = service.AddUser("Gagan", "leeee");
if (response.statusCode() == 201) {
Gson gson = new Gson();
System.out.println(response.asString());
PostUser[] userlist = gson.fromJson(response.asString(), PostUser[].class);
System.out.println(userlist[0].getCreatedAt());
System.out.println(response.statusCode());
}
}
}
Eclipse控制台输出-----
[{"name":"Gagan","job":"leeee"}]
null
201
邮递员输出
{
"name": "Gagan",
"job": "leee",
"id": "327",
"createdAt": "2019-02-08T07:42:50.664Z"
}
PostUser类
打包webservices.responsePOJO;
导入com.google.gson.annotations.Expose; 导入com.google.gson.annotations.SerializedName;
公共类PostUser {
@SerializedName("name")
@Expose
private String name;
@SerializedName("job")
@Expose
private String job;
@SerializedName("id")
@Expose
private String id;
@SerializedName("createdAt")
@Expose
private String createdAt;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
}