空手道模拟 - '如何使用密钥创建模拟以从 json 获取值



空手道模拟 - '如何使用密钥创建模拟以从 json 获取值。 在下面的示例中,我想使用 id 获取名称,我无法检索

响应.json

{

"2727": "西瓦", "2728":"卡维">

}

demo-mock.feature

功能:有状态模拟服务器

背景:

* def company = read('response.json')

场景: pathMatches('/companies/search/{id}}'(

* def name = company.id 
* def response = name

test.feature

功能:集成测试

背景:

* def port = karate.env == 'mock' ? karate.start('demo-mock.feature').port : 8080
* url 'http://localhost:' + port + '/companies/search'

@mock 方案:获取公司名称

Given path '2727'
When method get
Then status 200

阅读文档:https://github.com/intuit/karate/tree/master/karate-netty#pathparams

* def id = pathParams.id

最新更新