【发布时间】:2020-02-18 13:40:29
【问题描述】:
我目前正在使用 Wiremock 编写集成测试。目前,我将 id 和组织 id 定义为参数。与其对 50 个字段重复此过程,是否可以将 JSON 文件作为请求传递?即使用这个文件作为requestBody。
stubFor(post(urlEqualTo("/v1/transaction"))
.withRequestBody(
matchingJsonPath("$.data.id", containing("1")))
.withRequestBody(matchingJsonPath("$.data.organisation_id", containing("2")))
.willReturn(aResponse()
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withStatus(HttpStatus.CREATED.value())
.withBodyFile("create_successful_response.json")));
【问题讨论】:
-
requestBody 不是请求正文;请求正文由客户端传输。您设置的内容将在请求正文上执行。