【发布时间】:2022-02-27 16:34:11
【问题描述】:
空手道模拟-`如何创建模拟以使用键从 json 中获取值。 在下面的示例中,我想使用 id 获取名称,我无法检索
response.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'
@模拟 场景:获取公司名称
Given path '2727'
When method get
Then status 200
【问题讨论】:
标签: karate