response = res.when().post(a.getGetBankAPI()).then().extract() .response();
//Thread.sleep(1000);
int statuscode = response.getStatusCode();
System.out.println(statuscode);
try
{
Assert.assertEquals(statuscode, 200);
}
catch(AssertionError e)
{
org.testng.Assert.fail("Actual value is not equal to Expected value for");
}
System.out.println(getJsonPath(response, "error.message[0].msg"));
assertEqual(getJsonPath(response, "error.message[0].msg"), "branch should be 3 to 50 character long","Error for passing Empty Branch");
这里我的测试用例在步骤打印 ln 状态代码之后失败了,但它没有提到失败但它只是跳过并且在这里中止了总测试执行,如果你使用 printstacktrace(),它没有跳过但它是也没有被标记为失败
try
{
Assert.assertEquals(statuscode, 200);
}
catch(AssertionError e)
{
org.testng.Assert.fail("Actual value is not equal to Expected value for");
}
您使用 try 和 catch 块处理的方式可能导致测试被跳过而不是失败的问题。
在断言上使用 try catch 不是好的做法。但是如果你真的需要这个那么你可以像这样使用它
catch(AssertionError e)
{
throw new AssertionError("Actual value is not equal to Expected value for", e);
}
如果您使用的是 TestNg,那么您可以通过这种方式使用断言。所以你不需要使用任何try catch来打印消息
Assert.assertEquals("Actual","expected"," Actual result is not same as expected");