Karate 合约测试如何处理 API 版本控制?

问题描述 投票:0回答:1

我是空手道合同测试的新手。我有一个 Spring Boot 应用程序,我为它编写了一个空手道测试,如下所示:

Background:
  * call read('docker-operations.feature')

  * url 'http://localhost:8080'
  * def path = 'myController/filter'
  * def openApiSpec = read('schemas/filtering.json')
  * def requestSchema = openApiSpec.components.schemas.filtering_request
  * def responseSchema = openApiSpec.components.schemas.filtering_200_response
  # needs to be converted to String because if it stays as JSON, karate will automatically convert that JSON into Map in Java class
  * def requestSchemaString = karate.toString(requestSchema)
  * def responseSchemaString = karate.toString(responseSchema)
  * def validRequest = read('schemas/valid-request.json')
  * def invalidRequest = read('schemas/invalid-request.json')
  * def invalidResponse = read('schemas/invalid-response.json')

  Scenario: Valid Response Scenario

  Given path path
  And request validRequest
  When method POST
  Then status 200
  * print 'Schema JSON:', responseSchema
  * print 'Response JSON:', response
  * def responseString = karate.toString(response)
  And  assert Java.type('feature.JsonValidator').isValid(responseSchemaString, responseString)

顺便提一下,我正在使用生成的 openAPI 规范(filtering.json)。但我遇到了这种情况:我需要使用当前的 API 版本、以前的 API 版本以及我们支持的所有以前的 API 版本来运行测试。如果可能的话,如何用空手道处理这种情况?我知道使用 SPring cloud 我可以通过 Maven 来做到这一点。

java spring karate api-versioning
1个回答
0
投票

我认为这对于空手道来说不是合理的预期,这在很大程度上取决于您的环境以及如何设置以前和当前的版本。也许循环所有版本的数据驱动测试是可行的方法。

考虑到这不是由空手道直接支持的,但我知道一些团队已经在空手道上编写了一些例程来使其发挥作用。我们欢迎对空手道做出贡献,它是开源的。

就我个人而言,我认为仅仅测试模式(这就是你似乎正在做的事情)所获得的回报并不值得:https://www.linkedin.com/pulse/api-contract-testing-visual-guide -彼得-托马斯/

© www.soinside.com 2019 - 2024. All rights reserved.