2016-10-22 55 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實現的服務。

相關問題