在另一个 JSON 文件中使用 JSON 文件(用于代码可重用性)?有可能?(空手道/APITesting/SchemaValidation)



我正在处理大量API数据,我的计划是使用空手道进行模式验证。因为我有很多共享属性的项目我想创建JSON文件并调用在主JSON文件中,我有整个模式。

我知道我可以在功能文件中调用每个json,但我想知道是否有任何方法我可以把所有的模式放在一起,像一个谜题,从多个json文件在一个json文件中,只调用一个功能文件。

谢谢!附言:请救救我!

看一下这个例子:https://github.com/ptrthomas/karate-test/tree/main/src/test/java/examples/reuse

所以你可以" composition "在一个可重用的特性文件中包含多个JSON文件,如下所示:

@ignore
Feature:
Scenario:
* def first = read('first.json')
* def second = read('second.json')
* def schema = { first: '#(first)', second: '#[] second' }

然后当你想用这个来匹配时,注意call是如何在"共享"中完成的。Scope:

* call read('common.feature')
* def response = { first: { a: 1 }, second: [{ b: 'x' }] }
* match response == schema

最新更新