我的所有测试用例都遇到此错误。请大家帮忙看看是哪里出了问题?我是测试新手,如果这是一个愚蠢的问题,我很抱歉。
java.lang.AssertionError:1 个期望失败。 预期状态代码 <200> 与实际状态代码 <301> 不匹配。
@Test (priority=1)
public static void authSuccess(){
String id = "xxxxxxxxxx";
given().
param("id",id).
when().
post("/auth").
then().
statusCode(200).
body("content.id", equalTo(id));
}
@Test (priority=2)
public static void authFail(){
String id = "xxxxxxxxxx";
given().
param("id", id).
when().
post("/auth").
then().
statusCode(400).
body("errors[0]", equalTo("Incorrect ID"));
}
最佳答案
希望您在尝试自动化测试之前已经在 Postman/SoapUI 中进行了测试。
你在 postman 中也得到了 200 分。
几个指针
- 检查您是否使用相同的方法,例如 get/post。
- 仔细检查您正在使用的端点
- 确保您的 header 和参数在放心和 postman 之间正确。
希望这对您有所帮助!
关于java - 状态代码与实际状态代码不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46557916/