The JSR223 Assertion allows JSR223 script code to be used to check the status of the previous sample.
JSR223断言允许使用JSR223脚本代码去检查之前的取样的状态
使用场景:检查两个接口返回的值做比较来断言
JSR223断言的一些配置
//获取JSR223 Sample定义的urcic的值
def vurcic = vars.get(“urcic”);
//获取上一个sample定义的count
def vroomscount = vars.get(“count”);
log.info("-----------JSR223 Assertion 断言-------------");
log.info(vurcic);
log.info(vroomscount);
//判断urcic和count的值是否一致。并且根据断言结果做出提示
if(vurcic == vroomscount){
AssertionResult.setFailure(false);
AssertionResult.setFailureMessage(“ok”);
}
else{
AssertionResult.setFailure(true);
AssertionResult.setFailureMessage(“待关联房源数不一致”);
}
运行用例的时候,断言成功。
关于AssertResult 支持的方法
getFailureMessage()
Get the message associated with any failure or error.
getName()
Get the name of the assertion
getSearchableTokens()
Get a list of all tokens that should be visible to searching
isError()
Check if an error occurred while checking the assertion.
isFailure()
Check if the assertion failed.
setError(boolean e)
Set the flag indicating whether or not an error occurred while evaluating assertion failure clause.
setFailure(boolean f)
Set the flag indicating whether or not a failure occurred.
setFailureMessage(String message)
Set the failure message giving more details about a failure or error.
setResultForFailure(String message)
Convenience method for setting up failed results
setResultForNull()
Convenience method for setting up results where the response was null
toString()