首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在另一个类中使用一个类的属性

在另一个类中使用一个类的属性
EN

Stack Overflow用户
提问于 2022-06-27 08:28:50
回答 1查看 344关注 0票数 0

我试图将assertThat方法从身份验证类移到BDDStyledMethod类,但当前代码将生成以下错误:“steps.Authentication”中的“Creds(java.lang.String)”不能应用于'()'“

如何更正代码,使assertThat方法在BDDStyledMethod类中工作?

代码语言:javascript
运行
复制
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"));

    }

}
代码语言:javascript
运行
复制
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"));
    }
}
EN

Stack Overflow用户

回答已采纳

发布于 2022-06-27 08:56:19

问题在于Creds方法。它没有返回任何内容,而异常在这一行-> Authentication.Creds().response.statusLine()中引发

我们可以从Creds方法返回一个字符串,然后尝试在GetActivityById类中对返回的字符串应用assert()。

代码语言:javascript
运行
复制
    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();

        }

    }

代码语言:javascript
运行
复制
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"));
    }
}
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72769105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档