我试图将assertThat方法从身份验证类移到BDDStyledMethod类,但当前代码将生成以下错误:“steps.Authentication”中的“Creds(java.lang.String)”不能应用于'()'“
如何更正代码,使assertThat方法在BDDStyledMethod类中工作?
public class Authentication {
public static void Creds(String url){
RequestSpecification httpRequest=RestAssured.given()
.auth().oauth2(Authentication.login("user","password"));
Response response = httpRequest.get(url);
ResponseBody body=response.getBody();
body.prettyPrint();
System.out.println("The status received: " + response.statusLine());
assertThat("They are not the same",response.statusLine(),is("HTTP/1.1 200"));
}
}public class BDDStyledMethod {
public static void GetActivityById(){
Authentication.Creds("www.randomurl.com");
assertThat("They are not the same",Authentication.Creds().response.statusLine(),is("HTTP/1.1 200"));
}
}发布于 2022-06-27 08:56:19
问题在于Creds方法。它没有返回任何内容,而异常在这一行-> Authentication.Creds().response.statusLine()中引发
我们可以从Creds方法返回一个字符串,然后尝试在GetActivityById类中对返回的字符串应用assert()。
public class Authentication {
public static String Creds(String url){
RequestSpecification httpRequest=RestAssured.given()
.auth().oauth2(Authentication.login("user","password"));
Response response = httpRequest.get(url);
ResponseBody body=response.getBody();
body.prettyPrint();
System.out.println("The status received: " + response.statusLine());
return response.statusLine().toString();
}
}public class BDDStyledMethod {
public static void GetActivityById(){
String returned_str = Authentication.Creds("www.randomurl.com");
assertThat("They are not the same",returned_str,is("HTTP/1.1 200"));
}
}https://stackoverflow.com/questions/72769105
复制相似问题