如何解决Java测试RestAPI空指针.assertThatbody“ message” NullPointerException
在Eclipse的TestNG中运行方法.assertThat().body("message",equalTo("Successfully! Record has been fetched."))
时出现java.lang.NullPointerException: Cannot invoke method startsWith() on null object
错误。
但是它可以与.assertThat().body(containsString("Successfully! Record has been fetched."))
一起使用。
所有相关的依赖项已安装在pom.xml
中。
package restassuredTests;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.*;
import static org.hamcrest.Matchers.*;
public class Demo1_GET_Request {
@Test
public void GET_Request() {
System.out.println("Test: Into Get Request");
given()
.when()
.get("http://dummy.restapiexample.com/api/v1/employee/1")
.then()
.statusCode(200)
.header("Content-Type","application/json")
.assertThat().body("message",equalTo("Successfully! Record has been fetched.")) **<--- Error here**
.assertThat().body(containsString("Successfully! Record has been fetched."));
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。