使用场景大纲中的示例匹配每个
Match each using Examples from Scenario Outline
我发现使用 * match each response.xyz
非常强大,可以将对象结构测试与内容测试结合起来。有没有办法将它与 Examples
tables 和 <placeholder>
一起使用?
我有类似这样的东西,我想在 table 上使用示例 table:
* match each response.Services ==
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
Examples:
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
我明白了
"Services": [
{
"ServiceId": 3,
"Name": "Waltz",
"Description": "Waltzing like Matilda",
"InActive": false,
},
{
"ServiceId": 4,
"Name": "Foxtrot",
"Description": "",
"InActive": false,
},
返回作为回应。
显然,当我在 Examples:
中使用多行时,会导致多个测试。
我正在寻找的是根据预定义的值测试数组中的每个对象,但不知道它们将以什么顺序出现。并使用像 tables 生产这样的有序方法。
而不是 each
,试试这个:
* match response.Services contains
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
编辑:好的,另一种选择。顺便说一下,我至少可以想到 5 种不同的方式:P
Scenario:
* table data
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
* def expected = karate.map(data, function(x){ return { ServiceId: '#present', Name: x.Name, Description: '#present', InActive: x.Inactive} })
* match response.Services contains expected
EDIT2:如果你能控制整个table
:
Scenario:
* table expected
| Name | InActive | ServiceId | Description |
| "Foxtrot" | false | '#present' | '#present' |
| "Waltz" | false | '#present' | '#present' |
* match response.Services contains expected
我发现使用 * match each response.xyz
非常强大,可以将对象结构测试与内容测试结合起来。有没有办法将它与 Examples
tables 和 <placeholder>
一起使用?
我有类似这样的东西,我想在 table 上使用示例 table:
* match each response.Services ==
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
Examples:
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
我明白了
"Services": [
{
"ServiceId": 3,
"Name": "Waltz",
"Description": "Waltzing like Matilda",
"InActive": false,
},
{
"ServiceId": 4,
"Name": "Foxtrot",
"Description": "",
"InActive": false,
},
返回作为回应。
显然,当我在 Examples:
中使用多行时,会导致多个测试。
我正在寻找的是根据预定义的值测试数组中的每个对象,但不知道它们将以什么顺序出现。并使用像 tables 生产这样的有序方法。
而不是 each
,试试这个:
* match response.Services contains
"""
{
"ServiceId" : #present,
"Name" : <Name>,
"Description" : #present,
"InActive" : <Inactive>,
}
"""
编辑:好的,另一种选择。顺便说一下,我至少可以想到 5 种不同的方式:P
Scenario:
* table data
| ClientId | Name | Status | ErrorCode | Inactive |
| 400152 | "Foxtrot" | 200 | 0 | false |
| 400152 | "Waltz" | 200 | 0 | false |
* def expected = karate.map(data, function(x){ return { ServiceId: '#present', Name: x.Name, Description: '#present', InActive: x.Inactive} })
* match response.Services contains expected
EDIT2:如果你能控制整个table
:
Scenario:
* table expected
| Name | InActive | ServiceId | Description |
| "Foxtrot" | false | '#present' | '#present' |
| "Waltz" | false | '#present' | '#present' |
* match response.Services contains expected