空手道API测试工具中的模糊匹配

时间:2018-12-13 12:00:40

标签: json testing karate fuzzy

我们最近开始在我们当前正在开发的项目中使用空手道作为我们的集成测试工具,最近我遇到了一个问题,我想知道为什么会这样。我们来看一下:

我们在所有API中进行的测试之一是响应时间。当我们开始创建测试时,我们已经创建了一系列通用功能,可用于许多不同的API测试。这些功能之一就是testGetAll.feature,其中我们将参数,端点,可选的参数列表,身份验证密钥和可选的响应时间作为参数发送。

在调用服务之前,我们有以下代码:

* def rTime = (__arg.rTime == '#notnull' ? __arg.rTime : MEDIUM_RESPONSE_TIME)

然后,为了测试它是否正常工作,我编写了以下内容:

* print "argRtime : " + __arg.rTime
* print __arg.rTime == '#notnull' 
* print "rTime : " + rTime 

结果我得到了:     argRtime = 3000     假     rTime = 500

如果__arg.rTime不为null,为什么此条件为假?

2 个答案:

答案 0 :(得分:2)

我想所有空手道内置的模糊匹配标记只能与match一起使用。

__arg.rTime == '#notnull'

是简单的javascript评估,而不是空手道match,因此这里将RHS视为字符串并进行评估。

但是

* match __arg.rTime == '#notnull'

将完美运行。

但是根据您的逻辑,您可以尝试

* def rTime = ( __arg.rTime != null ? __arg.rTime : MEDIUM_RESPONSE_TIME)
  

空手道模糊匹配标记只能与匹配

一起使用

答案 1 :(得分:2)

您可以在the karate object中的var template = ` <table class="objList" > <tr data-ng-repeat="z in colStorageItems | orderBy: \'-name\' track by $index"> <th class = "col" data-ng-repeat="y in z | orderBy: \'name\' track by $index"> {{y}} </th> </tr> </table> `; 上使用模糊匹配器,如下所示:

karate.match