java - 是否可以将 spring rest 文档与 spock 一起使用

标签 java groovy spock spring-restdocs

我在我的 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/

相关文章:

java - JEE7 : best way to create another thread that never exits

java - 使用自定义类加载器加载 Java 运行时和 API 类

gradle - Gradle 3.4:使用ConfigSlurper构建配置文件

jenkins - 如何测试 Jenkins 插件是否安装在 Pipeline DSL (Groovy)

java - javax.servlet.http.Cookie 的 getDomain() 返回 null

testing - Grails 不能使用 Spock 框架?

java - 除非我对其调用append(),否则JTextArea不会显示

java - if 与 if/else 语句?

gradle - 在运行测试的同时获得jacoco代码覆盖率

java - 如何通过 Kotlin Gradle 和 -D 为我的测试提供系统属性