2016-10-22 36 views
2

我有我的Java应用程序中使用spock和groovy构建测试用例。是否有可能弹簧安置文档添加到项目,而无需使用模拟MVC或restassured是否有可能使用spock的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' 
    } 
} 

回答

4

您可以使用Spring REST文档与斯波克,但你必须要使用Mock MVC或REST Assured来测试和记录您的RESTful服务,因为这些是REST Docs支持的两个测试框架。

从REST Docs的角度来看,使用Spock与使用JUnit非常相似,因为您继续使用JUnitRestDocumentation规则。您可以在REST Docs的Grails示例的ApiDocumentationSpec中看到此操作。该示例演示了如何使用REST Docs和REST Assured测试和记录使用Grails实现的服务。

相关问题