@Test
public void getProfile() {
RestAssured.baseURI = URL.baseURL;
Response res = given().header(URL.contentType,
URL.cookieType).when().get(URL.getURL).then().assertThat().
statusCode(200).and().extract().response();
String data = res.asString();
System.out.println(data);
}
以下是测试运行的输出:
{"status_code":401,"message":"Authentication failed."}
TestNG现在将此情况标记为PASS,即使响应不符合预期。我怎样才能使这个工作?我想只使用assertThat语句。
您必须将测试结果保存为布尔值或数值。
稍后您必须使用Assert将预期测试结果与实际测试结果进行比较:
Boolean testPassed = isTestPassed();
Assert.assertTrue("The test result is: "+testPassed,testPassed);
数字比较:
long testValue = getTestResponseCode();
Assert.assertEquals("Actual test respoonse code is: "+testValue,testValue);