如何解决是否可以在合同的特定 json body 字段中设置多个值?
例如,我有 2 个 必填 字段:姓名和年龄。 如果我使用 Spring Cloud Contract 那么我需要用合同描述几个文件:
- 请求正文为
{"name": "test","age": 99}
- 请求正文为
{"name": null,"age": 99}
- 请求正文为
{"name": "test","age": null}
或者我可以在一份合同中描述它并从中生成几个测试?
解决方法
如果您打开 Spring Cloud Contract (https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/project-features.html#contract-dsl) 的文档,您会看到它写在第一句话中。
Spring Cloud Contract 支持在单个合同中定义多个合同 文件。
import org.springframework.cloud.contract.spec.Contract
[
Contract.make {
name("should post a user")
request {
method 'POST'
url('/users/1')
}
response {
status OK()
}
},Contract.make {
request {
method 'POST'
url('/users/2')
}
response {
status OK()
}
}
]
在提问之前,请务必阅读文档。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。