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

我尝试运行这个 Rest Assured TestNG 测试:


@Test

public 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;

}


慕沐林林
浏览 213回答 2
2回答

慕村225694

您应该删除 RestAssured.baseURI = "localhost:8080"; 因为 baseURI 默认是本地主机,如果你想设置端口,你应该使用 RestAssured.port=8080;
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java