我在我的 Java 应用程序中使用 spock 和 groovy 构建了测试用例。是否可以在不使用 mock mvc 或 restassured 的情况下将 spring rest 文档添加到该项目
这是我的项目的片段
import groovyx.net.http.RESTClient;
import spock.lang.Specification;
class FindIdeasSpec extends Specification{
def host ="http://www.localhost.com:8080/v1/"
def path = "communities/"
def client = new RESTClient(host)
def id = 1
def "verify the links"() {
when: "request ideas list"
def response = client.get(path: path + id + '/ideas')
then: "returns parent and self link"
with(response) {
status == 200
data.links.rel == ['self']
data.links.href[0] == host + path + id + '/ideas'
}
}
最佳答案
您可以将 Spring REST Docs 与 Spock 一起使用,但您必须使用 Mock MVC 或 REST Assured 来测试和记录您的 RESTful 服务,因为这是 REST Docs 支持的两个测试框架。
从 REST Docs 的角度来看,使用 Spock 与使用 JUnit 非常相似,因为您继续使用 JUnitRestDocumentation 规则。您可以在 ApiDocumentationSpec
中看到实际效果来自 REST Docs 的 Grails 示例。该示例展示了如何使用 REST Docs 和 REST Assured 测试和记录使用 Grails 实现的服务。
关于java - 是否可以将 spring rest 文档与 spock 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40193694/