是否可以使用带有spock的spring rest docs

Sud*_*ppa 2 java groovy spock spring-restdocs

我在我的java应用程序中使用spock和groovy构建了测试用例.是否可以在不使用模拟mvc或restassured的情况下将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'
    }
}
Run Code Online (Sandbox Code Playgroud)

And*_*son 6

您可以将Spring REST Docs与Spock一起使用,但您必须使用Mock MVC或REST Assured来测试和记录您的RESTful服务,因为它们是REST Docs支持的两个测试框架.

从REST Docs的角度来看,使用Spock非常类似于继续使用JUnitRestDocumentation规则时使用JUnit.您可以ApiDocumentationSpec从REST Docs的Grails示例中看到这一点.该示例演示了如何使用REST Docs和REST Assured测试和记录使用Grails实现的服务.