我想将一些JSON数据导入我的测试中 为了文档,我应该这样做:
* def data = read('classpath:init/data.json')
我已使用以下内容创建了我的JSON文件:
{
"name": "ehsan"
}
这是我的代码:
Background:
* def data = call read('classpath:init/data.json')
Scenario:
* print data
但它没有打印出来并说:
16:11:30.898 [main] WARN com.intuit.karate - not a js function or feature file: read('classpath:init/data.json') - [type: JSON, value: com.jayway.jsonpath.internal.JsonContext@7d61eccf]
答案 0 :(得分:2)
是的,请仔细阅读错误消息(和文档) - “调用”JSON文件没有任何意义,只要您read
它 - 您已经拥有可重复使用的数据。就这样做:
Background:
* def data = read('classpath:init/data.json')
Scenario:
* print data
答案 1 :(得分:2)
下面的代码是正确的:
* def data = read('classpath:init/data.json')
只有你必须删除[call]