是否可以在条件语句中使用空手道“匹配”? [英] Is it possible to use karate 'match' inside conditional statement?
问题描述
在此处查找示例。
def a =条件? 空手道比赛声明:空手道比赛声明
是否可以这样做?
不推荐将其用于测试,因为
karate.match()
的结果将以 {pass:'#boolean',message:'#string'}
如果以上选项均不起作用-这意味着您正在做的事情确实复杂,因此编写Java互操作代码/ a 来处理此问题
Find the example here.
def a = condition ? " karate match statement " : "karate match statement"
Is it possible to do something like this??
This is not recommended practice for tests because tests should be deterministic.
The right thing to do is:
- craft your request so that the response is 100% predictable. do not worry about code-duplication, this is sometimes necessary for tests
- ignore the dynamic data if it is not relevant to the
Scenario
- use conditional logic to set "expected value" variables instead of complicating your
match
logic - use self-validation expressions or schema-validation expressions for specific parts of the JSON
- use the
if
keyword and call a second feature file - in some cases
karate.abort()
can be used to conditionally skip / exit early
That said, if you really insist on doing this in the same flow, Karate allows you to do a match
via JS in 0.9.6.RC4 onwards.
See this thread for details: https://github.com/intuit/karate/issues/1202#issuecomment-653632397
The result of karate.match()
will return a JSON in the form { pass: '#boolean', message: '#string' }
If none of the above options work - that means you are doing something really complicated, so write Java interop / code to handle this
这篇关于是否可以在条件语句中使用空手道“匹配”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!