使用Spock和Groovy作为集成测试,请放心

使用Spock和Groovy作为集成测试,请放心,groovy,integration-testing,spock,rest-assured,Groovy,Integration Testing,Spock,Rest Assured,在spock框架中使用REST-assured框架。 这是对关闭的可能的副本的回答,看起来很不错。你有更复杂测试的例子吗?对于大型测试或大量输入数据,它会变得不那么有用吗?@RocketRaccoon很抱歉,这个项目是商业性的,我的合同不允许我发布代码。但我将其用于整个REST集成测试,包括OAuth2的授权。 package cz.audatex.audanext.auth.endpoint.v1.member.settings import com.jayway.restassured.R

在spock框架中使用REST-assured框架。
这是对关闭的

可能的副本的回答,看起来很不错。你有更复杂测试的例子吗?对于大型测试或大量输入数据,它会变得不那么有用吗?@RocketRaccoon很抱歉,这个项目是商业性的,我的合同不允许我发布代码。但我将其用于整个REST集成测试,包括OAuth2的授权。
package cz.audatex.audanext.auth.endpoint.v1.member.settings

import com.jayway.restassured.RestAssured
import org.librucha.ServerApp
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.SpringApplicationConfiguration
import org.springframework.boot.test.WebIntegrationTest
import spock.lang.Specification
import spock.lang.Unroll

@SpringApplicationConfiguration(classes = ServerApp.class)
@WebIntegrationTest(randomPort = true)
class Test extends Specification {

    @Value('${local.server.port}')
    private int port

    def setup() throws Exception {
        RestAssured.port = port
    }

    @Unroll
    def "Get services as '#accessor.role' [#iterationCount]"() {
        given:
            def request = given()
                 .accept(JSON)
                 .auth().oauth2(getToken(accessor.name))
                 .log().all()
        when:
            def response = request.with().get("/api/v1/services")
        then:
            response.then().log().all()
                 .statusCode(status)
                 .spec(specification)
        where:
            accessor                                    || status       || specification
            [name: 'user-login', role: 'ordinary user'] || SC_FORBIDDEN || expect().body('code', equalTo('access_denied'), 'description', equalTo('Access is denied'))
            [name: 'admin-login', role: 'super admin']  || SC_OK        || expect().body('id', contains(1, 2, 3, 4))
    }
}