Api 如何使用空手道工具和功能文件比较包含数组的2个JSON对象
场景的文件Api 如何使用空手道工具和功能文件比较包含数组的2个JSON对象,api,testing,karate,Api,Testing,Karate,场景的文件 所有文件都在同一目录中 标题更新请求.json {id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]} {id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
- 所有文件都在同一目录中
{id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
标题更新响应.json
{id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
标题更新错误请求。json
{id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
标题更新错误响应.json
{id: 12, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 12, name: 'New Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
图书记录。功能
Feature: CRUD operation on the book records.
Background:
* def signIn = call read('classpath:login.feature')
* def accessToken = signIn.accessToken
* url baseUrl
Scenario: Change title of book in the single book-record.
* json ExpResObject = read('classpath:/book-records/title-update-response.json')
* json ReqObject = read('classpath:/book-records/title-update-request.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 200 }
Scenario: Change title of book in the non-existing book-record.
* json ExpResObject = read('classpath:/book-records/title-update-error-request.json')
* json ReqObject = read('classpath:/book-records/title-update-error-response.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 400 }
更新。功能
Feature: CRUD operation on the book records.
Background:
* def signIn = call read('classpath:login.feature')
* def accessToken = signIn.accessToken
* url baseUrl
Scenario: Change title of book in the single book-record.
* json ExpResObject = read('classpath:/book-records/title-update-response.json')
* json ReqObject = read('classpath:/book-records/title-update-request.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 200 }
Scenario: Change title of book in the non-existing book-record.
* json ExpResObject = read('classpath:/book-records/title-update-error-request.json')
* json ReqObject = read('classpath:/book-records/title-update-error-response.json')
* call read('classpath:/book-records/update.feature') { Token: #(accessToken), ReqObj: #(ReqObject), ResObj: #(ExpResObject), StatusCode: 400 }
功能:更新图书记录
Scenario: Update single book-record.
Given path '/book-record'
And header Authorization = 'Bearer ' + __arg.Token
And header Content-Type = 'application/json'
And request __arg.ReqObj
When method put
Then status __arg.StatusCode
And response == __arg.ExpectedResponse
场景1的实际API响应为:
{name: 'New Hello', config:[{username: 'abc', password: 'xyz'},{username: 'qwe', password: 'tyu'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
场景2的实际API响应为:
{name: 'New Hello', config:[{username: 'abc', password: 'xyz'},{username: 'qwe', password: 'tyu'}]}
{Error: 'not found', Message: 'The provided Book is not found.'}
问题:我应该如何验证update.feature文件中的响应,因为问题是如果我使用#^^配置进行更改,这对场景2不起作用,而response==\u arg.ExpectedResponse对场景1不起作用?这是典型的测试工程。如果有人告诉你测试需要“重复使用”,请不要听那个人的 你有两种情况,一种是快乐的道路,另一种是消极的道路。我提供了你应该如何写下下面的消极路径,其余的由你决定
Scenario: Change title of book in the non-existing book-record.
Given path 'book-record'
And header Authorization = 'Bearer ' + accessToken
And request {id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
When method put
Then status 400
And response == {Error: 'not found', Message: 'The provided Book is not found.'}
看看有多干净?测试中不需要“极端”重复使用。如果你仍然坚持要一个超级通用的可重用的特性文件来处理你所有的边缘情况,那你就是在给自己制造麻烦。看看您现有的测试变得多么不可读
编辑:因为我经常将这个问题作为如何不编写测试的示例引用给其他人,所以我想更清楚地说明我的观点,并添加几个链接以供参考
有时在测试中“重复你自己”是可以的。测试不一定非得如此。空手道是一种使您能够在一两行中进行HTTP调用或JSON操作的工具。当你开始尝试这样的“重复使用”时,实际上弊大于利。例如,您现在需要查看多个文件以了解您的测试正在做什么
如果你不相信我,也许你会相信谷歌:这是测试工程的经典。如果有人告诉你测试需要“重复使用”,请不要听那个人的 你有两种情况,一种是快乐的道路,另一种是消极的道路。我提供了你应该如何写下下面的消极路径,其余的由你决定
Scenario: Change title of book in the non-existing book-record.
Given path 'book-record'
And header Authorization = 'Bearer ' + accessToken
And request {id: 00, name: 'Old Hello', config:[{username: 'qwe', password: 'tyu'},{username: 'abc', password: 'xyz'}]}
When method put
Then status 400
And response == {Error: 'not found', Message: 'The provided Book is not found.'}
看看有多干净?测试中不需要“极端”重复使用。如果你仍然坚持要一个超级通用的可重用的特性文件来处理你所有的边缘情况,那你就是在给自己制造麻烦。看看您现有的测试变得多么不可读
编辑:因为我经常将这个问题作为如何不编写测试的示例引用给其他人,所以我想更清楚地说明我的观点,并添加几个链接以供参考
有时在测试中“重复你自己”是可以的。测试不一定非得如此。空手道是一种使您能够在一两行中进行HTTP调用或JSON操作的工具。当你开始尝试这样的“重复使用”时,实际上弊大于利。例如,您现在需要查看多个文件以了解您的测试正在做什么
如果你不相信我,也许你会相信谷歌:Ya。没错。没错。