为了账号安全,请及时绑定邮箱和手机立即绑定

放心 - post() - java.lang.NullPointerException:

放心 - post() - java.lang.NullPointerException:

慕沐林林 2021-07-15 17:05:52
我尝试运行这个 Rest Assured TestNG 测试:@Testpublic void test_createIssue() {    RestAssured.baseURI = "localhost:8080";    String sessionCookie = Reusable.getSessionCookie();    given().            header("Content-Type", "application/json").            header("Cookie", sessionCookie).            body("{\n" +                    "    \"fields\": {\n" +                    "       \"project\":\n" +                    "       {\n" +                    "          \"key\": \"PROJ\"\n" +                    "       },\n" +                    "       \"summary\": \"REST ye merry gentlemen.\",\n" +                    "       \"description\": \"Creating of an issue using project keys and issue type names using the REST API\",\n" +                    "       \"issuetype\": {\n" +                    "          \"name\": \"Zadanie\"\n" +                    "       }\n" +                    "   }\n" +                    "}").            when().            post("/rest/api/2/issue").            then().            statusCode(201);}getSessionCookie()在第 4 行调用方法:static String getSessionCookie() {    RestAssured.baseURI = "localhost:8080";    Response response = given().            header("Content-Type", "application/json").            body("{\"username\": \"admin\", \"password\": \"admin\"}").            when().            post("/rest/auth/1/session").            then().            statusCode(200).            extract().response();    JsonPath responseJson = rawToJson(response);    String sessionName = responseJson.get("session.name");    String sessionValue = responseJson.get("session.value");    return sessionName + "=" + sessionValue;}
查看完整描述

2 回答

?
慕村225694

TA贡献1880条经验 获得超4个赞

您应该删除 RestAssured.baseURI = "localhost:8080"; 因为 baseURI 默认是本地主机,如果你想设置端口,你应该使用 RestAssured.port=8080;


查看完整回答
反对 回复 2021-07-29
  • 2 回答
  • 0 关注
  • 212 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信