2

我在我的 java 应用程序中使用 spock 和 groovy 构建了测试用例。是否可以在不使用 mock mvc 或 reassured 的情况下将 spring rest docs 添加到这个项目

这是我的项目的片段

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'
    }
}
4

1 回答 1

7

您可以将 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 实现的服务。

于 2016-10-22T16:15:35.867 回答