空手道-能够动态确定空手道中的比赛类型以进行验证 [英] Karate - Ability to dynamically decide the type of match in karate for verification

查看:60
本文介绍了空手道-能够动态确定空手道中的比赛类型以进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说,我们为不断发展的服务器编写了以下脚本脚本

Lets say we scripted the scenarios following way for our evolving servers

Actual server v1 response 
response = { id: "1", name: "karate" }
Mocking client v1 schema 
schema = { id: "#string", name: "#string }
* match response == schema

Actual server v2 response
response = { id: "2", name: "karate", value: "is" }
Mocking client v2 schema
schema = { id: "#string", name: "#string, value: "#string" }
* match response == schema

Actual server v3 response
response = { id: "3", name: "karate", value: "is", description: "easy" }
Mocking client v3 schema
schema = { id: "#string", name: "#string", value: "#string", description: "#string" }
* match response == schema

类似地,为了对不断发展的服务器进行向后兼容性测试,我们按照以下方式编写方案脚本

Similarly for backward compatibility testing of our evolving servers, we script the scenarios following way

Actual server v3 response
response = { id: "3", name: "karate", value: "is", description: "easy" }
Mocking client v1 schema 
schema = { id: "#string", name: "#string }
* match response contains schema

Actual server v2 response
response = { id: "2", name: "karate", value: "is" }
Mocking client v1 schema 
schema = { id: "#string", name: "#string }
* match response contains schema

Actual server v1 response 
response = { id: "1", name: "karate" }
Mocking client v1 schema 
schema = { id: "#string", name: "#string }
* match response contains schema

建议是能够在match语句中使用某种标记,该标记可以动态地决定我们在测试过程中进行的匹配的类型. 可以说,标志的名称是SOMEFLAG,我们提供了我们在测试期间想要进行的匹配(在karate-config.js中设置以实现全局效果)

Proposal is to be able to use some kind of flag in match statement that dynamically decides the kind of match we do during testing. Lets say that the name of flag is SOMEFLAG and we provide the kind of match we want to do during testing (set in karate-config.js for global effect)

var SOMEFLAG = "contains"; 
OR
var SOMEFLAG = "==";

现在在这种情况下,我们会进行跟踪

Now in scenario we do following

# Depending on what is set in karate-config.js, it will use either contains or == for verification.
* match response SOMEFLAG schema

有可能在空手道中做到这一点吗?

Is it possible to do this in karate ?

还要注意,这个想法的成功实际上取决于 https://github.com/intuit /karate/issues/826 由于使用包含匹配功能进行嵌套嵌套对象匹配.

Also note that success of this idea really depends on https://github.com/intuit/karate/issues/826 due to ability match nested object using contains match.

推荐答案

我个人坚决反对这种想法,因为它会使您的测试难以理解.一旦开始,这是一个湿滑的斜坡.举一个例子,当您尝试过多地重复使用时会发生什么(是的,在测试自动化中重复使用可能是一件坏事,如果您不同意,我真的不在乎:)-参见:https://stackoverflow.com/a/54126724/143475

Personally, I am strongly against this idea because it will make your tests less readable. It is a slippery slope once you start this. For an example of what happens when you attempt too much re-use (yes, re-use can be a bad thing in test automation, and I really don't care if you disagree :) - see this: https://stackoverflow.com/a/54126724/143475

我会做的是这样的:

* def lookup = 
"""
{
  dev: { id: "#string", name: "#string },
  stage: { id: "#string", name: "#string, value: "#string" },
  preprod: { id: "#string", name: "#string", value: "#string", description: "#string" }
}
"""
* def expected = lookup[karate.env]
* match response == expected

编辑-我觉得我们在讨论之后进行的更改也将解决您的问题-或至少给您一些新的想法: https://github.com/intuit/karate/issues/810

EDIT - I have a feeling that the change we made after this discussion will also solve your problem - or at least give you some new ideas: https://github.com/intuit/karate/issues/810

这篇关于空手道-能够动态确定空手道中的比赛类型以进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆